save variables to table in for loop

조회 수: 20 (최근 30일)
Supwolf
Supwolf 2020년 3월 6일
편집: Sindar 2020년 3월 6일
I want to save variables into a table
this is my code now
nfiles = length(imagefiles);
for ii=1:nfiles
currentfilename = imagefiles(ii).name;
currentimage = imread(currentfilename);
currentfilename = convertCharsToStrings(currentfilename)
.
.
.
end
I want to get a result like this
aaa
bbb
.
.
.
through all the name of a image
  댓글 수: 2
Sindar
Sindar 2020년 3월 6일
Do you want the image saved in the table, or just the filename? Also, to be clear, do you want a Matlab table, to save to a file, or to print to the command window?
Supwolf
Supwolf 2020년 3월 6일
Only filename And save to file Sorry that I tell not clear

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

답변 (1개)

Sindar
Sindar 2020년 3월 6일
편집: Sindar 2020년 3월 6일
Assuming you just want the final result and don't care about when it prints the filenames:
fileID = fopen('filenametable.txt','w');
fprintf(fileID,'%s\n',imagefiles.name)
fclose(fileID);
nfiles = length(imagefiles);
for ii=1:nfiles
currentfilename = imagefiles(ii).name;
currentimage = imread(currentfilename);
currentfilename = convertCharsToStrings(currentfilename)
.
.
.
end
if you want it to print at each iteration:
fileID = fopen('filenametable.txt','w');
nfiles = length(imagefiles);
for ii=1:nfiles
currentfilename = imagefiles(ii).name;
fprintf(fileID,'%s\n',currentfilename)
currentimage = imread(currentfilename);
currentfilename = convertCharsToStrings(currentfilename)
.
.
.
end
fclose(fileID);

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by