How do I print out a sequence of numbers on a text file using fprintf??

15 ビュー (過去 30 日間)
Syamsundar Menon Murali Mohan
Syamsundar Menon Murali Mohan 2021 年 9 月 8 日
%Print values into text file
centx = props.Centroid(1)
centy = props.Centroid(2)
fprintf('imagenumber',centx, centy);
I've already got the values of the centx and centy, and they are generated fine. The only issue is I would like a numbered list for each value of centx and cent y.
e.g.
image number cent x cent y
1 0.1 0.2
2 0.2 0.4
3 0.3 0.6
4 0.4 0.8
etc.
I hope someone can help me with this!

回答 (1 件)

KSSV
KSSV 2021 年 9 月 8 日
fid = fopen('test.txt','w') ;
fprintf(fid,'%s %s %s\n','Imaage Number','centx','centy') ;
n = 10 ;
for i = 1:n
fprintf(fid,'%d %f %f\n',i,rand,rand) ;
end
fclose(fid) ;
  10 件のコメント
Walter Roberson
Walter Roberson 2021 年 9 月 9 日
Under what circumstances is the count restarting? Is it restarting once for each file? Are you doing multiple runs with the same sets of files and appending to the output? Are you doing runs over different directories and appending to the output?
Is it possible that you are detecting multiple regions for each image and wanting to save the centroid for each region? If so then it is not clear to me that the numbering should be continuing through all of the files: how would you determine where each file ended in the list?
For that matter, even if there is only one output per file, how do you make it clear which output line corresponds to which input file?
Syamsundar Menon Murali Mohan
Syamsundar Menon Murali Mohan 2021 年 9 月 9 日
  1. I am essentially detecting the centroid for a whole range of images
  2. Each image has its own centroid value, and I'm trying to include that within a numbered list.
  3. The reason that I'm doing a numbered list is so that I can eventually transfer it into an Excel file and plot the different centroids based on the values that I extracted over the whole range of images
Would that not be possible? I'm a beginner in MATLAB so I was hoping I could get some clarification if this may be possible.

サインインしてコメントする。

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by