read data file
read data file
(OP)
Hi,
I am trying to read a .txt data file. But somehow can only get "''". Below is my code of write file, and then read file.
%write data:
x=0:0.1:1;
y=[x;exp(x)];
fid=fopen ('C:\exptab.txt', 'w');
%fprintf(fid,'Exponential function\n');
fprintf(fid, '%6.2f %12.8f\n',y);
fclose (fid);
%read data
fid=fopen('C:\exptab.txt','r');
AA=fscanf(fid,'%6.3f %13.2f\n');
fclose(fid);
Can anybody please to help me find the error?
Thanks,
bj
I am trying to read a .txt data file. But somehow can only get "''". Below is my code of write file, and then read file.
%write data:
x=0:0.1:1;
y=[x;exp(x)];
fid=fopen ('C:\exptab.txt', 'w');
%fprintf(fid,'Exponential function\n');
fprintf(fid, '%6.2f %12.8f\n',y);
fclose (fid);
%read data
fid=fopen('C:\exptab.txt','r');
AA=fscanf(fid,'%6.3f %13.2f\n');
fclose(fid);
Can anybody please to help me find the error?
Thanks,
bj





RE: read data file
Use
CODE
CODE
RE: read data file
Thanks for the help. But I tried the code you gave me, The result still shows ''. Any more suggestions?
bj
RE: read data file
just not able to use "fscanf" command.
bj
RE: read data file
%
disp(' ')
disp(' Select file input method ');
disp(' 1=external ASCII file ');
disp(' 2=file preloaded into Matlab ');
file_choice = input(');
%
if(file_choice==1)
[filename, pathname] = uigetfile('*.*');
filename = fullfile(pathname, filename);
%
fid = fopen(filename,'r');
THM = fscanf(fid,'%g %g',[2 inf]);
THM=THM';
else
THM = input(' Enter the matrix name: ');
end
%
t=double(THM(:,1));
y=double(THM(:,2));
%
Tom Irvine
www.vibrationdata.com
RE: read data file
I tried your program, and it worked!!
Really appreciated.
bj
RE: read data file
RE: read data file
I actually read the docs and copied the example of the fscanf function to my program, but it didn't work. The result always show "''".That's why I posted my question here. I'm not the one you implied that I didn't spend time to read documents, and just wanted a quick answer.BTW, I haven't figured out why my original program show the '' result. I will try to understand and if I do, I will post the reason here.
Regards,
bj