May 22, 2005 #1 D davyzhu 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
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
May 22, 2005 #2 E elbadry Full Member level 6 Joined May 6, 2005 Messages 347 Helped 72 Reputation 144 Reaction score 10 Trophy points 1,298 Location Egypt Activity points 3,884 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
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
May 24, 2005 #3 G ghbolivar Full Member level 1 Joined Jul 25, 2001 Messages 97 Helped 7 Reputation 14 Reaction score 0 Trophy points 1,286 Activity points 764 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);
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);