From: samik bhattacharya on 13 Jul 2010 12:33 Hi all, I have a data file in the following format: Step = 1 z = 0.0000 U_pitot= 8.030 U = 7.168 To read this, I used the following line of codes: fp=fopen('c:\Samik\test\data.txt','r'); p=fscanf(fp,'Step =%f\t'); q=fscanf(fp,'z =%f\t'); r=fscanf(fp,'U_pitot=%f\t'); s=fscanf(fp,'U=%f'); fclose(fp); But problem is, fscanf is reading only upto U_pitot, but not U. So in the workspace i am getting variavles like ans= 0 fp=3 p=1 q=0 r=8.0300 U=[] Now I can not figure out why this is happenning. I will be glad to get some help on this Regards Samik
From: dpb on 13 Jul 2010 12:58 samik bhattacharya wrote: > Hi all, > I have a data file in the following format: > Step = 1 z = 0.0000 U_pitot= 8.030 U = 7.168 > To read this, I used the following line of codes: > fp=fopen('c:\Samik\test\data.txt','r'); > p=fscanf(fp,'Step =%f\t'); > q=fscanf(fp,'z =%f\t'); > r=fscanf(fp,'U_pitot=%f\t'); > s=fscanf(fp,'U=%f'); > fclose(fp); > > But problem is, fscanf is reading only upto U_pitot, but not U. So in > the workspace i am getting variavles like > ans= 0 > fp=3 > p=1 > q=0 > r=8.0300 > U=[] > Now I can not figure out why this is happenning. I will be glad to get > some help on this One would guess there's something in the data file that doesn't quite match what you think. I'd do something like fp=fopen('c:\Samik\test\data.txt','rt'); % Note the 't' for safety s = fgetl(fp); % get the full line t = findstr(s,'\t'); % see where tabs really are n = lenght(t); % and how many fp = fclose(fp); Now do the results of the above look as you expect? You might also consider doc textscan --
From: samik bhattacharya on 13 Jul 2010 13:18 dpb <none(a)non.net> wrote in message <i1i644$6ua$1(a)news.eternal-september.org>... > samik bhattacharya wrote: > > Hi all, > > I have a data file in the following format: > > Step = 1 z = 0.0000 U_pitot= 8.030 U = 7.168 > > To read this, I used the following line of codes: > > fp=fopen('c:\Samik\test\data.txt','r'); > > p=fscanf(fp,'Step =%f\t'); > > q=fscanf(fp,'z =%f\t'); > > r=fscanf(fp,'U_pitot=%f\t'); > > s=fscanf(fp,'U=%f'); > > fclose(fp); > > > > But problem is, fscanf is reading only upto U_pitot, but not U. So in > > the workspace i am getting variavles like > > ans= 0 > > fp=3 > > p=1 > > q=0 > > r=8.0300 > > U=[] > > Now I can not figure out why this is happenning. I will be glad to get > > some help on this > > One would guess there's something in the data file that doesn't quite > match what you think. > > I'd do something like > > fp=fopen('c:\Samik\test\data.txt','rt'); % Note the 't' for safety > s = fgetl(fp); % get the full line > t = findstr(s,'\t'); % see where tabs really are > n = lenght(t); % and how many > fp = fclose(fp); > > Now do the results of the above look as you expect? > > You might also consider > > doc textscan > > --Hi, Thanks for your reply. After I ran your code, i got t=[], n=0; So it means number of tabs=0.I deleted all the tabs from my code. But now it is not reading anything atall Samik
From: dpb on 13 Jul 2010 15:18 samik bhattacharya wrote: > dpb <none(a)non.net> wrote in message > <i1i644$6ua$1(a)news.eternal-september.org>... >> samik bhattacharya wrote: >> > Hi all, >> > I have a data file in the following format: >> > Step = 1 z = 0.0000 U_pitot= 8.030 U = 7.168 >> > To read this, I used the following line of codes: .... >> > > But problem is, fscanf is reading only upto U_pitot, but not U. So .... >> > Now I can not figure out why this is happenning. I will be glad to >> get > some help on this >> >> One would guess there's something in the data file that doesn't quite >> match what you think. >> >> I'd do something like >> >> fp=fopen('c:\Samik\test\data.txt','rt'); % Note the 't' for safety >> s = fgetl(fp); % get the full line >> t = findstr(s,'\t'); % see where tabs really are >> n = lenght(t); % and how many >> fp = fclose(fp); >> >> Now do the results of the above look as you expect? >> >> You might also consider >> >> doc textscan >> >> --Hi, > Thanks for your reply. After I ran your code, i got t=[], n=0; So it > means number of tabs=0.I deleted all the tabs from my code. But now it > is not reading anything atall Sorry if this is a duplicate-- OK, now we know it isn't a tab-delimited file format. I'd still recommend looking at textscan() for this but... I missed this, too, first go but--look _very_ carefully at the format string and the data line at the location where the first go-round failed and see if you see the problem therein. --
From: samik bhattacharya on 13 Jul 2010 15:53 dpb <none(a)non.net> wrote in message <i1ieag$f37$1(a)news.eternal-september.org>... > samik bhattacharya wrote: > > dpb <none(a)non.net> wrote in message > > <i1i644$6ua$1(a)news.eternal-september.org>... > >> samik bhattacharya wrote: > >> > Hi all, > >> > I have a data file in the following format: > >> > Step = 1 z = 0.0000 U_pitot= 8.030 U = 7.168 > >> > To read this, I used the following line of codes: > ... > >> > > But problem is, fscanf is reading only upto U_pitot, but not U. So > ... > >> > Now I can not figure out why this is happenning. I will be glad to > >> get > some help on this > >> > >> One would guess there's something in the data file that doesn't quite > >> match what you think. > >> > >> I'd do something like > >> > >> fp=fopen('c:\Samik\test\data.txt','rt'); % Note the 't' for safety > >> s = fgetl(fp); % get the full line > >> t = findstr(s,'\t'); % see where tabs really are > >> n = lenght(t); % and how many > >> fp = fclose(fp); > >> > >> Now do the results of the above look as you expect? > >> > >> You might also consider > >> > >> doc textscan > >> > >> --Hi, > > Thanks for your reply. After I ran your code, i got t=[], n=0; So it > > means number of tabs=0.I deleted all the tabs from my code. But now it > > is not reading anything atall > > Sorry if this is a duplicate-- > > OK, now we know it isn't a tab-delimited file format. > > I'd still recommend looking at textscan() for this but... > > I missed this, too, first go but--look _very_ carefully at the format > string and the data line at the location where the first go-round failed > and see if you see the problem therein. > > --hi, I did not quite get your procedure. To use textscan I need to know the exact format. But I tried to use c=textscan(fp,'%s %f\t %s %f\t %s %f\t %s %f'); OR c=textscan(fp,'%s %f %s %f %s %f %s %f '); none worked anyway, thanks again for your effort samik
|
Next
|
Last
Pages: 1 2 Prev: resid function - System Identification Toolbox Next: restoration of signal |