So I was wondering about the following:
I have a simulation export from LTSpice with the following structure:
time V(vin) V(vout) I(B1) I(D1) I(Rload) I(V1)Step Information: D=200m (Run: 1/13)0.000000000000000e+000 1.291820e+001 1.247644e+001 2.187000e+000 2.186138e+000 2.970581e+000 -7.852747e-0017.902717741844912e-011 1.291820e+001 1.247649e+001 2.187000e+000 2.188567e+000 2.970593e+000 -7.836857e-0018.444024477795836e-011 1.291820e+001 1.247649e+001 2.187000e+000 2.188719e+000 2.970593e+000 -7.835863e-0019.165766792397068e-011 1.291820e+001 1.247650e+001 2.187000e+000 2.188895e+000 2.970594e+000 -7.834706e-001..Step Information: D=250m (Run: 2/13)(More data, same structure)
I am unable to read all lines as a string and keep the formatting intact, most likely due to the tabs that separate the data values. Is there a way to replace tabs by spaces with the `textscan` function or a way to keep the formatting?
clear all;fid = fopen('s11.txt','r');S = textscan(fid, '%s', 'delimiter', '\n', 'whitespace', '', 'TreatAsEmpty', '');S = S{1};fclose(fid);% Find subheaders
idx = find(contains(S,'Step'));cycle_data = cell(length(idx),1) ;for i = 1:length(idx)-1 cycle_data{i} = S(idx(i)+1:idx(i+1)-1);endcycle_data{end} = S(idx(end)+1:end) ;
Which yields a matrix with 13 entries (all cycles/data subheaders separated) but the problem I get is that the data values are concatenated. More concise:
In an entry I get lines like this:
0.000000000000000e+0001.291820e+0011.247644e+0012.187000e+0002.186138e+0002.970581e+000-7.852747e-001
Instead of what I want:
0.000000000000000e+000 1.291820e+001 1.247644e+001 2.187000e+000 2.186138e+000 2.970581e+000 -7.852747e-001
Thanks in advance!
Ps. An alternative solution is also completely fine for me.
Best Answer