How do I print out a sequence of numbers on a text file using fprintf??
4 views (last 30 days)
Show older comments
Syamsundar Menon Murali Mohan
on 8 Sep 2021
Commented: Syamsundar Menon Murali Mohan
on 9 Sep 2021
%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 Comments
Answers (1)
KSSV
on 8 Sep 2021
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 Comments
Walter Roberson
on 9 Sep 2021
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?
See Also
Categories
Find more on Text Analytics Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!