Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Write vectors to a file in Matlab?

Status
Not open for further replies.

davyzhu

Advanced Member level 1
Advanced Member level 1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
Hello all,

How to Write vectors to a file in Matlab? And read from the file? The easiest way?
For example, A=[1 3 5 7 9],B=[2 7 6 8 9 10 11 12],C= ...and I want to write/read these vectors to a file, thanks!

Regards,
Davy
 

I think the easiest way is use the "load" and "save" commands

To save a vector x and a vector y to a file names "Myfile" do the following:

save 'Myfile' x y

Note that you can save any number of vectors to the same file, just separate them by a space

To load those vectors into workspace use:

load 'Myfile' x y


Hope this is useful
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
use fprintf

example:

x = 0:.1:1; y = [x; exp(x)];
fid = fopen('exp.txt','w'); %file's name mode write
fprintf(fid,'%6.2f %12.8f\n',y); %write in file
fclose(fid);
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top