Struct contents reference from a non-struct array object.

5 ビュー (過去 30 日間)
Stelios Fanourakis
Stelios Fanourakis 2018 年 4 月 23 日
コメント済み: Stelios Fanourakis 2018 年 4 月 27 日
folder = 'C:\Echo Images\Stelios\FDB';
file_temp = sprintf('%s\\*.bmp', folder);
filearray = dir(file_temp);
s = max(size(filearray));
for i=1: 1: s
[p, f] = fileparts(file_temp(i).name);
imgname=strcat(folder,'\\',filearray(i).name);
I = imread(imgname);
dicomwrite(I, [imgname '.dcm']);
end
I get the error at [p, f] = fileparts(file_temp(i).name); line. PLease help!!

採用された回答

Jan
Jan 2018 年 4 月 23 日
You want the output of dir, not the one of sprintf:
file_temp = sprintf('%s\\*.bmp', folder);
filearray = dir(file_temp);
for i = 1:s
[p, f] = fileparts(filearray(i).name); % file_temp => filearray
By the way:
  • Please format your code in the forum using the "{} Code" button. It is a good idea to post readable code.
  • An easier method to create the file pattern:
% file_temp = sprintf('%s\\*.bmp', folder)
file_temp = fullfile(folder, '*.bmp');
  • The field .name contains the file name only, so there is no need to split it by fileparts.
p = filearray(i).folder;
f = filearray(i).name;
But you not need p or f at all.
  • Use fullfile instead of strcat:
imgname = fullfile(folder, filearray(i).name)
  1 件のコメント
Stelios Fanourakis
Stelios Fanourakis 2018 年 4 月 27 日
Thank you so much Jan. Your answer was really helpful!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by