i want to save names of the images(frame_0000, frame_0001, frame_0003........) in a text file by reading them from a folder.

1 回表示 (過去 30 日間)
i want to save names of the images(frame_0000, frame_0001, frame_0003........) in a text file by reading them from a folder. somehow i am getting errors while writing the code. As i am new to MatLab please help me. Waiting for your response.
  1 件のコメント
Geoff Hayes
Geoff Hayes 2018 年 8 月 14 日
sidra - somehow i am getting errors while writing the code. What is the code? What are the errors?

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2018 年 8 月 14 日
編集済み: Stephen23 2018 年 8 月 14 日
D = 'directory where images are';
S = dir(fullfile(D,'*.jpg'));
% Save filenames:
[fid,msg] = fopen('names.txt','wt');
assert(fid>=3,msg)
fprintf(fid,'ImageName\n')
fprintf(fid,'%s\n',S.name)
fclose(fid);
% Load files:
for k = 1:numel(S)
Im = imread(fullfile(D,S(k).name));
...
end
This uses S.name to generate a comma-separated list, and so each filename gets printed to the textfile.
  9 件のコメント
Stephen23
Stephen23 2018 年 8 月 15 日
編集済み: Stephen23 2018 年 8 月 15 日
@sidra Rafique: your code duplicates printing the filenames, and you need to add a separator/delimiter character between the filename and the value. Try something like this:
c = {S.name};
c(2,:) = num2cell(d);
[fid,msg] = fopen('names.txt','wt');
assert(fid>=3,msg);
fprintf(fid, '%s,%s\n','Imagename','Diameter');
fprintf(fid, '%s,%3.4f\n',c{:});
fclose(fid);
Note how I used the comma as a delimiter, and the filenames are included in c, so you do not need to print them again.
sidra Rafique
sidra Rafique 2018 年 8 月 15 日
still its not working. but i have used xlswrite() to save in excel instead of text document. and its working and its more simpler. Thanks for your help.

サインインしてコメントする。

その他の回答 (1 件)

Yuvaraj Venkataswamy
Yuvaraj Venkataswamy 2018 年 8 月 14 日
In your case you can use below command.
if true
imwrite(frames, fullfile(f_folder,sprintf ('%frame_04d.jpg', nFrame)));
end
  1 件のコメント
sidra Rafique
sidra Rafique 2018 年 8 月 14 日
編集済み: Stephen23 2018 年 8 月 14 日
i am done with reading all the 1000 images(frame_0000, frame_0001, frame_0003...., frame_1000) from a folder using below code:
Directory= //path where images are located
Imgs = dir(fullfile(Directory,'*.jpg'));
for j=1:length(Imgs)
Img = imread(fullfile(Directory,Imgs(j).name)); % Read image
end
but now i am still unable to make a text file consisting of names of all the read images with same name format in column.i.e;
ImageName
frame_0000
frame_0001
.
.
.
for that i am using below code:
fid = fopen('names.txt','w');
fprintf(fid, '%5s\n','Imagename');
fprintf(fid, '%i\n',j);
fclose(fid);
but its only showing last read image if i do %i but with %s its showing nothing.. please help me in finding solution.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by