Reputation: 41
Currently I am using read comma-separated value (CSV) file which is csvread
in my code. what if I want to read value row by row, which my value is not seperated by comma?
This is my code for save data:
%% Save data to .txt
fid=fopen('MyFile1.txt','w');
fprintf(fid, '%f \n', AngleValue');
fclose(fid);
This is the save values
Then I run a code using csvread
I = csvread('MyFile1.txt');
but I got an error. can anyone give an idea, probably I should change how I save my data or how can I read the data row by row. Thanks
Upvotes: 1
Views: 67
Reputation: 41
Problem solved. I found out that i just have to put coma (,) when i fprintf my saved data.
My previous code:
fprintf(fid, '%f \n', AngleValue');
My corrected code:
fprintf(fid, '%f,', AngleValue');
So now i can use csvread in my program.
Upvotes: 0
Reputation: 114786
There are other alternatives to csvread
. Try dlmread
instead
I = dlmread('MyFile.txt');
A more general approach,
Why are you writing AngleValue
as text files? Why not use save
and load
in a more Matlab-ish fashion? read and write in binary format, tailored for Matlab use?
save('MyFile.mat','AngleValue'); %// save to binary Mat file
Once you saved the variable, you can read it:
load('MyFile.mat'); %// that's it!
Upvotes: 1