Usage of textscan format spec input argument to read text file data at repeated specified locations

Dear Friends
Could anyone provide insight with reading the following data
I would like to read the text file data for the first value of every node (total 235 nodes) and store it as a 235 x 1 column array, X. (0.31158E+02, 0.38774E+02, 0.51027E+02,...)
Similarly, I would also want to read the file data for the second value for each of the 235 nodes given ( -0.15094E+03, -0.16236E+03, -0.17097E+03,... ) and store it as a 235 x 1 column array, Y.
and as well the 3rd value for each of the 235 nodes and store it as a 235 x 1 column array, Z
I am trying to use textscan to read the file data using an appropriate format spec repeated for 235 nodes times.
>> formatspec= '%f %*[\n]';
>> X=textscan(fid,formatspec,235)
X =
cell
[31.158000000000001]
what sort of format spec can i use to form the 235 x 1 column array for X (first value of every node) , Y (2nd value of every node) and Z (3rd value of every node) ?

 Accepted Answer

filename = 'data.txt';
fid = fopen(filename, 'rt');
fmtspec = 'Node: %*f\n\n%f%f%f\n%*f%*f%*f';
XYZ = textscan(fid, fmtspec);
fclose(fid);
X = XYZ{1};
Y = XYZ{2};
Z = XYZ{3};

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!