Prev: Dealing with a blank datenum result?
Next: Difference Mean Opinion Score (DMOS) for image/video/Voice Quality?
From: Khanh on 9 Aug 2010 12:10 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <b05e6dd2-e760-4dc2-95bf-fcb34b9e239a(a)l14g2000yql.googlegroups.com>... > Use fopen to open the file. Then start a loop where you call > fgetl(). Then (in the loop) test the string for "NO = 123" using > strfind(), strcmpi() or similar functions. When found, break out of > the loop. Then get the next line with fgetl() and use sscanf() to > extract the numbers out of it. Thank you. Here is what I did... for those who need it clear clc fid=fopen('mydata.txt'); for i=1:1:13 tline=fgetl(fid); if strfind(tline,'NO =')==77 linumb=i; end end fclose(fid); fid=fopen('mydata.txt') pre_linumb=linumb-1 for i=1:pre_linumb tline=fgetl(fid); end tline=fgetl(fid); a=textscan(tline,'%s = %f %s = %f %s = %f'); a{5} a{6}
From: ImageAnalyst on 9 Aug 2010 12:28 I'm not sure how your strfind would find "NO = 123" Also, you should move your fclose to the end. No need to reopen it and read past all those lines because that is exactly what you just did. No need to do it again.
From: Khanh on 9 Aug 2010 12:53
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <55923b6d-10f2-4a47-97ca-76d99e488795(a)e15g2000yqo.googlegroups.com>... > I'm not sure how your strfind would find "NO = 123" > Also, you should move your fclose to the end. No need to reopen it > and read past all those lines because that is exactly what you just > did. No need to do it again. First, strfind finds "NO=" by its position in line(77). It's the samefor all of my files. That's how it does. Thanks for your suggest. Here what I changed to: clear clc fid=fopen('mydata.txt'); for i=1:1:13 tline=fgetl(fid); if strfind(tline,'NO =')==77 linumb=i; a=textscan(tline,'%s = %f %s = %f %s = %f'); a{5} a{6} end end fclose(fid); |