Create new data sheet from fprintf code outputs

조회 수: 1 (최근 30일)
Aysen Barut
Aysen Barut 2022년 12월 30일
댓글: Walter Roberson 2022년 12월 30일
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
Walter Roberson
Walter Roberson 2022년 12월 30일
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()

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
Rik 2022년 12월 30일
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
Aysen Barut
Aysen Barut 2022년 12월 30일
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 2022년 12월 30일
Change the square brackets to round braces. That will give you a cell array instead, which allows mixing data types.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by