How to Write file names of multiple images to a csv file.?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!