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

2 views (last 30 days)
%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!

Answers (1)

KSSV
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
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?
Syamsundar Menon Murali Mohan
  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.

Sign in to comment.

Categories

Find more on Text Analytics Toolbox in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!