필터 지우기
필터 지우기

How to Write file names of multiple images to a csv file.?

조회 수: 4 (최근 30일)
Renjith V Ravi
Renjith V Ravi 2017년 10월 31일
답변: Walter Roberson 2017년 10월 31일
From the code below,I got the file names of multiple images from a folder.
clear all
close all
clc
Directory = 'Images_folder\';
Imgs = [dir(fullfile(Directory,'*.bmp')); dir(fullfile(Directory,'*.jpg'));
dir(fullfile(Directory,'*.png'));dir(fullfile(Directory,'*.tif'))];
% D = dir('images');
ID = 1;MDMF=2;IDMF=3;HD=4;UHD=5;
m=[ID,MDMF,IDMF,HD,UHD];%comma separation is necessary for errorles result
for j=1:length(Imgs)
Img = imread(fullfile(Directory,Imgs(j).name)); % Read image
% figure
% imshow(Img)
end
headers={'File_Name',};
for i=1:length(Imgs)
f_name =Imgs(i).name;
f_name = f_name(1:end-4);
filename = sprintf('%s',f_name);
disp(filename)
csvwrite('Myfile.csv',filename)
end
My aim is to write these file names into first column of Myfile.csv.Bu I am getting error.Please help me

답변 (1개)

Walter Roberson
Walter Roberson 2017년 10월 31일
You cannot use csvwrite() or dlmwrite() to selectively overwrite columns. You would need to use xlswrite() or writetable() to selectively overwrite columns.
If you are just trying to create a new file with those entries as the only content, then the easiest way is to do it "manually". No loop is required:
fid = fopen('Myfile.csv', 'wt');
[~, f_names] = cellfun(@fileparts, {Imgs.name}, 'uniform', 0);
fprintf(fid, '%s\n', f_names{:});
fclose(fid);

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by