Create new data sheet from fprintf code outputs
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Walter Roberson
el 30 de Dic. de 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()
Respuestas (1)
Rik
el 30 de Dic. de 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 comentarios
Rik
el 30 de Dic. de 2022
Change the square brackets to round braces. That will give you a cell array instead, which allows mixing data types.
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!