MATLAB: Extracting multiple sets of scientific notation data

arraydata extractionformatMATLABscientific notationsscanf

Hello all,
I am trying to extract some data for plotting and I've been struggling to get the data structered how I want it. I have a results file attached which is where I'm getting my data. I want to pull out the first section of data which represents node numbers and xyz coordinates and store this data as a Nx4 array (N happens to be 12881 for this file). I also want to pull out the very last temperature data set (at the very end, the NDTEMP block just above the RFL block) and store that as a 61×2 array.
The main problem I've been having so far is that the coordinates and temperature data is in exponential/scientific notation, and sscanf() doesn't seem to want to read them. I've tried formating sscanf() with %11.5E, %11.5e with no luck. The dimensions of the arrays come out correct if I format sscanf() with %d and %f but I want to keep the scientific notation if I can.
Any tips or advice would be greatly appreciated!
Thank you for your time,
Best,
John

Best Answer

Try this sscanf format string:
'%d%f'
However your file-importing code is rather complex. Here is a simpler method using textscan, which reads the two sections that you are apparently interested in:
myp = '.'; % path to where the file is saved.
fnm = fullfile(myp,'Quarter_Cone_10deg_CASE_No_FR.txt');
[fid,msg] = fopen(fnm,'rt');
assert(fid>=3,msg)
% 1. Read first matrix:
C = textscan(fid,'-1%f%f%f%f','HeaderLines',12,'CollectOutput',true);
% 2. Locate last NDTEMP line:
idx = NaN;
while ~feof(fid) % read every remaining line in the file...
str = strtrim(fgets(fid));
if strncmp(str,'-4 NDTEMP',10)
idx = ftell(fid); % location of this line within the file.
end
end
fseek(fid,idx,'bof'); % go back to the last NDTEMP line.
% 3. Read second matrix:
D = textscan(fid,'-1%f%f','HeaderLines',1,'CollectOutput',true);
fclose(fid);
And checking:
>> size(C{1})
ans =
12881 4
>> C{1}
ans =
1 0 0 0
2 0.026303 0 0.062219
3 0.039788 0.051913 0.051913
4 0.026303 0.062219 0
5 0.0127 2.2789e-15 0
6 0.03574 0 0.055006
7 0.047963 0.045664 0.045664
.... lots of lines here
12883 1.4438 0.24538 0.20958
12884 1.4438 0.24442 0.20875
12885 1.4438 0.24345 0.20793
12886 1.4438 0.24248 0.2071
12887 1.4438 0.24152 0.20628
>> size(D{1})
ans =
61 2
>> D{1}
ans =
1 2116.5
2 1975.5
10 1702.6
16 1445.4
22 1288.9
... lots of lines here
634 1162.1
635 1156.7
636 1151.8
637 1147.5
638 1144.4