Are the cell arrays in the Image field the correct sizes? why am i wrong?

1 回表示 (過去 30 日間)
DONG MIN JEONG
DONG MIN JEONG 2019 年 11 月 20 日
コメント済み: Karla Ramirez 2020 年 1 月 13 日
folders = dir("photos");
folders = string({folders.name});
folders = folders(~startsWith(folders,"."))
% Preallocate the structure crashImages
crashImages(length(folders)) = struct("Name",folders(end),"Images",cell(1));
for k = 1:length(folders)
photos = dir("photos\" + folders(k));
photos = string({photos.name});
photos = photos(~startsWith(photos,'.'));
% preallocate the cell array images
images = cell(length(photos),1);
for kk = 1:length(photos)
im = imread("photos\" + folders(k) + "\" + photos(kk));
images{kk} = im;
end
crashImages(k).Name = folders(k);
crashImages(k).Images = images;
clear images
end
crashImages
  1 件のコメント
Stephen23
Stephen23 2019 年 12 月 26 日
編集済み: Stephen23 2019 年 12 月 26 日
It is simpler and more robust to explicitly remove only the '.'and '..' names, and only keep folders' names (by using the isdir field):
S = dir('photos');
F = setdiff({S([S.isdir]).name},{'.','..'})

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

回答 (1 件)

Harsha Priya Daggubati
Harsha Priya Daggubati 2019 年 12 月 23 日
編集済み: Harsha Priya Daggubati 2019 年 12 月 26 日
Hi,
Can you provide more information on what is not turning out as expected or the error you are getting.
  2 件のコメント
Stephen23
Stephen23 2020 年 1 月 6 日
Cetengfei Zhang's "Answer" moved here:
Hi, I am wondering if you solved this problem. Because I am also stucked in this section with 99% completion.
This question detail is from the Matlab self-paced course: Matblab Programming Techniques. 4.3 Preallocation: (6/6) Preallocation of Structure and Cell Arrays. task 2.
Preallocate memory for the cell array 'images' that is created within the outer for loop
However I always get error even the official solution is used.
Karla Ramirez
Karla Ramirez 2020 年 1 月 13 日
Hi!
I had the same issue and I opened a thechnical support case reporting the problem, and they told me that it was a known issue and that they are working on it.
The solution is to replace every instance of "\" with "/". Thats where the problem is.
Have a nice day.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by