octave/matlab read text file line by line and save only numbers into matrix -
i have question regarding octave or matlab data post processing. have files exported fluent below:
"surface integral report" mass-weighted average static temperature (k)
crossplane-x-0.001 1242.9402 crossplane-x-0.025 1243.0017 crossplane-x-0.050 1243.2036 crossplane-x-0.075 1243.5321 crossplane-x-0.100 1243.9176
and want use octave/matlab post processing. if read first line line, , save lines "crossplane-x-" new file, or directly save data in lines matrix. since have many similar files, can make plots calling titles. go trouble on identify lines contain char "crossplane-x-". trying things this:
clear, clean, clc; % open file , read line line fid = fopen ("h20h22_alonghgpath_temp.dat"); % save full lines new file if chars inside txtread = fgetl (fid) num_of_lines = fskipl(fid, inf); char = 'crossplane-x-' i=1:num_of_lines, if char in fgetl(fid) [x, nx] = fscanf(fid); print x endif endfor fclose (fid);
would shed light on issue ? using right function ? thank you.
here's quick way specific file:
>> s = fileread("myfile.dat"); % collect file contents string >> c = strsplit(s, "crossplane-x-"); % first cell header, rest data >> m = str2num (strcat (c{2:end})) % concatenate datastrings, convert numbers m = 1.0000e-03 1.2429e+03 2.5000e-02 1.2430e+03 5.0000e-02 1.2432e+03 7.5000e-02 1.2435e+03 1.0000e-01 1.2439e+03
Comments
Post a Comment