Monday, 15 February 2010

Reading with Matlab specific lines from a file and converting them to numerical values -



Reading with Matlab specific lines from a file and converting them to numerical values -

i create code in matlab optimizes ansys study, want check ansys output file , see if results acceptable or not.

this code has imputs parameters used ansys create model. these parameters alter @ each iteration, @ each iteration different output file created.

let's more specific. below, there illustration of output file:

line 1 blabla

line 2 blabla

. . .

line 10000 maximum values line 10001 values1 2.31 4.56 5.69 8.64 0.25 9.70 . . line 35000 maximum values line 35001 values2 2.25 . . line 70000 total values3 2503.4

all want see if first 2 values in bold below limits of problem (i.e 9.70<15 , 2.25<7). if are, store 3rd value in bold in matrix. if not, go next iteration.

i'm pretty new programming , matlab instructions little confusing.

any ideas welcome!

thanks in advance!

**edit:** that's entire code far:

x1=linspace(26,60,3)'; x2=linspace(104,70,3)'; r=linspace(3,10,3)'; vec={x1',x2',r'}; combs=combvec(vec{:})'; seqv=zeros(i,1); tic i=1:length(combs); fid=fopen('c:\users\vaioss\desktop\ergasia ymk\test\aa.txt','w+'); fprintf(fid,'*set,x1,%7.4f \r\n',combs(i,1)); fprintf(fid,'*set,x2,%7.4f \r\n',combs(i,2)); fprintf(fid,'*set,r,%7.4f \r\n',combs(i,3)); fclose(fid); fid=fopen('c:\users\...','r+'); fclose(fid); dos('"c:\program files\ansys inc\v150\ansys\bin\winx64\ansys150.exe" -p ...'); fid=fopen('c:\users\...','r'); j=1:10152; tline=fgetl(fid); end match = textscan(tline, '%s %f %f %f %f %f', '\n')'; seqv(i) = cell2mat(match(6,1)); if seqv(i)>67.2887; fclose(fid); go on end end fclose all; toc

if have unknown number of lines of varying format before info want, easiest way along these lines

1) utilize fgetl fetch lines 1 @ time (obviously if know can safely skip first 3000 lines or whatever, so)

2) utilize strfind check if you've nail values1 line. if so, parse line , check if value within limits.

then repeat values2 , values3 if required, or move onto next file , repeat. if there's chance have files in list don't contain these strings, you'll want way of handling case nail eof before finding them.

matlab file lines numerical

No comments:

Post a Comment