Hey everyone.
I have a function that analyses an image and returns numerical values about it in several variabels.
Imagine I run my code and have the following data
a1=2; a2=4; a3=0; a4=8;
now I want my code to write this values in a .txt in the following way: 2,4,0,8
I want to be capable of analysing several images in the folder and to keep all the results in the same .txt file, with all the values separated by commas.
Thanks in advance!

 채택된 답변

Geoff
Geoff 2012년 5월 22일

4 개 추천

This opens the file once (overwriting if it already exists) and writes your results one line at a time.
fid = fopen( 'results.txt', 'wt' );
for image = 1:N
[a1,a2,a3,a4] = ProcessMyImage( image );
fprintf( fid, '%f,%f,%f,%f\n', a1, a2, a3, a4);
end
fclose(fid);
Alternatively, you could open the file in 'append' mode, write the line, and close it again each time through the loop.
doc fopen

댓글 수: 4

David Fernández
David Fernández 2017년 5월 23일
이동: Image Analyst 2025년 7월 29일
Thanks! Simple, usefull.
Charles Miller
Charles Miller 2019년 2월 6일
Okay, but how do you CREATE the file to output to?
Carlos José
Carlos José 2019년 3월 13일
This code already creates one txt file...
you can see it better using this code (try it on your matlab):
b = [65 66 67 68 69];
criptografia = char(b);
fid = fopen('output.txt','wb');
fwrite(fid, criptografia, 'char');
fclose(fid);
Huy Le Van
Huy Le Van 2021년 11월 30일
Hi.
how do you write file .txt ? in here we have those space .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

질문:

2012년 5월 22일

이동:

2025년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by