Import or Export a Sequence of Files
조회 수: 2 (최근 30일)
이전 댓글 표시
I have been trying to export photos on MATLAB. With a.bmp, b.bmp and c.bmp works perfectly, but wrting *.bmp gives me an error. Could you help me out please.
Thanks
clc; clear all;
% paths = fullfile('c:\','users','fenec','Desktop','Cam_1',{'a.bmp'; 'b.bmp'; 'c.bmp'});
paths = dir(fullfile('c:\','users','fenec','Desktop','Cam_1','*.bmp'));
for R = 1:length(paths)
temp = char(paths(R));
I = imread(temp);
figure;
imshow(I, []);
end
댓글 수: 2
Stephen23
2021년 2월 27일
I don't see how this approach would ever work without error:
S = dir();
char(S(1))
Most likely you would be much better off just using the standard approach of using indexing and fieldname to access the structure content (just as they were designed for):
채택된 답변
Cris LaPierre
2021년 2월 27일
Perhaps the issue is that paths is a structure containing several fields and not just the path. Look at the dir documentation page for more.
The fields are
- name
- folder
- date
- bytes
- isdir
- datenum
Perhaps modify your code to be
for R = 1:length(paths)
temp = fullfile(paths(R).folder,paths(R).name);
I = imread(temp);
figure;
imshow(I, []);
end
댓글 수: 4
Stephen23
2021년 3월 18일
편집: Stephen23
2021년 3월 18일
@Luca Fenech: download, unzip, and use NATSORTFILES (following its documentation of course):
For example:
P = fullfile('C:\','users','fenec','Desktop','Cam 1');
S = dir(fullfile(P,'*.bmp'));
C = natsortfiles({S.name}); % sort filenames alphanumerically.
for k = 1:numel(C)
F = fullfile(P,C{k});
I = imread(F);
figure;
imshow(I,[]);
end
You can also sort the structure S by using the second output from NATOSRTFILES, which is the sort index.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!