Text file spacing values so they start at the same point on each new line
Mostra commenti meno recenti
How can I create a text file where the values in the file start at the same point for each line? Like this (basically line up the beginning of each value with the one above it):
3.695652174 -48.04347826 23.18181818 4 1 TEST1
-18.47826087 -11.08695652 30.90909091 4 1 TEST2
40.65217391 -77.60869565 0 4 1 TEST3
18.47826087 33.26086957 0 4 1 TEST4
This is what I have right now, and it is returning a text file with what I want, but the values are 'misaligned':
k=1;
output=strings(80,1);
l=size(EEG_band.dipfit.model,2)
nodefile = fopen('output.node', 'w');
for i = 1:l
% Check if the value in the third column is below the threshold
temp = EEG_band.dipfit.model(i).rv
if temp < 0.15
% If it is, add the values in the first and fourth columns to the
% output cell array and .node file
tempposxyz=EEG_band.dipfit.model(i).posxyz;
tempstring = sprintf('%0.4f %0.4f %0.4f 4 1 %s\n', tempposxyz(1), tempposxyz(2), tempposxyz(3), EEG_band.dipfit.model(i).areadk);
output(k,1) = tempstring;
fprintf(nodefile, tempstring);
k=k+1;
end
end
output=output(output~='');
% Write the values in the output cell array to a text file
fclose(nodefile)
The output from this is below:
3.6957 -48.0435 15.4545 4 1 superiorparietal R
-11.0870 -33.2609 23.1818 4 1 superiorparietal L
3.6957 -70.2174 15.4545 4 1 superiorparietal R
-3.6957 -33.2609 38.6364 4 1 superiorparietal L
25.8696 -77.6087 7.7273 4 1 lateraloccipital R
11.0870 -55.4348 7.7273 4 1 superiorparietal R
18.4783 -25.8696 46.3636 4 1 superiorparietal R
Any help is appreciated!
2 Commenti
Walter Roberson
il 3 Apr 2023
What is the difference between this and https://www.mathworks.com/matlabcentral/answers/1939939-make-values-or-words-in-a-text-file-start-at-the-same-point-in-each-line?s_tid=srchtitle ?
Emma Jacobs
il 3 Apr 2023
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Structures in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!