Create new data sheet from fprintf code outputs

2 visualizzazioni (ultimi 30 giorni)
I'm working on my code. My code is calculede after the some operation and finally output like this;
%%
if [value] ~= 0
if Diff<3 && Diff>-3
fprintf('\n %4f En "%s" Name , Comment:"%s", Dif:%.2f , Int(%%):%.2f , FD:%4f.\n' , En ,Name, comment , Dif, int, FD )
end
end
outputs:
86 En "X1" Name , Comment:"Y", Dif:0.68 , Int(%):3.56 , FD:0.92258
181 En "X2" Name , Comment:"Y", Dif:1.17 , Int(%):57.00 , FD:0.873798
241 En "X3" Name , Comment:"Y", Dif:1.36 , Int(%):7.27 , FD:0.887565
258 En "X3" Name , Comment:"Y", Dif:0.15 , Int(%):18.41 , FD:0.989895
351 En "X3" Name , Comment:"Y", Dif:1.05 , Int(%):35.60 , FD:0.940446
352 En "X4" Name , Comment:"Y", Dif:1.05 , Int(%):35.60 , FD:0.940332
605 En "X3" Name , Comment:"Y", Dif:1.17 , Int(%):45.49 , FD:0.961645
605 En "X4" Name , Comment:"Y", Dif:1.17 , Int(%):45.49 , FD:0.961579
1392 En "X5" Name , Comment:"Y", Dif:2.28 , Int(%):99.85 , FD:0.965726
I tried get a matrix from fprintf outputs are inculude Name and FD values with that code like this
%%
if [value] ~= 0
if Diff<3 && Diff>-3
fprintf('\n %4f En "%s" Name , Comment:"%s", Dif:%.2f , Int(%%):%.2f , FD:%4f.\n' , En ,Name, comment , Dif, int, FD )
fds=[Name,FD]
end
end
but it doesn't work. İ couldn't find another solution.
  1 Commento
Walter Roberson
Walter Roberson il 30 Dic 2022
Some people might be thinking of suggesting that you assign the output of fprintf to something that you save. However the returned output of fprintf is the number of items converted, not the text. To get the text you would use sprintf() or compose()

Accedi per commentare.

Risposte (1)

Rik
Rik il 30 Dic 2022
Your loop is overwriting the variable every iteration. You should replace this:
fds=[Name,FD]
With this:
fds=[fds;Name,FD];
(don't forget to put fds=[]; at the start of your code)
A better idea is to create a suitably large array at the start of the code and index it in your loop.
  2 Commenti
Aysen Barut
Aysen Barut il 30 Dic 2022
I changed my code according your directions and its output only .X5 size En times
like
' X5
X5
X5
X5
X5'
but i need a matrix from outputs like;
X1 0.92258
X2 0.873798
X3 0.887565
X3 0.989895
X3 0.940446
X4 0.940332
X3 0.961645
X4 0.961579
X5 0.965726
first colomun is Name and second one is FD values.
Rik
Rik il 30 Dic 2022
Change the square brackets to round braces. That will give you a cell array instead, which allows mixing data types.

Accedi per commentare.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by