Create new data sheet from fprintf code outputs
조회 수: 1 (최근 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
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
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
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!