How do I print out a sequence of numbers on a text file using fprintf??
2 次查看(过去 30 天)
显示 更早的评论
%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!
0 个评论
回答(1 个)
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
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Analytics Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!