Dot indexing is not supported for variables of this type.
3 次查看(过去 30 天)
显示 更早的评论
I faced this problem here. Please help me. I already try with give solution .
image_files = [];
for f = isfolder(image_path)
if f.endsWith([".jpg",".jpeg",".png", ".PNG"]) //problem is here
image_files.append(f);
end
end
Problem
Dot indexing is not supported for variables of this type.
Error in undistortion>undistorb_images (line 51)
if f.endsWith([".jpg",".jpeg",".png", ".PNG"])
2 个评论
DGM
2021-8-17
编辑:DGM
2021-8-17
You're going to have to explain what exactly you're trying to do here, because this code doesn't make any sense.
% what is image_path? is it a scalar string or char vector?
% is it a string array or a cell array of chars?
image_path = ???;
image_files = [];
% assuming image_path specifies multiple files,
% isfolder() will output a logical vector.
% f will be scalar logical, and the loop steps through each value
% but they're never used for anything
% if you're intending to only look at paths which are directories
% then why is the inner conditional looking to see if they're image files?
for f = isfolder(image_path)
% f is a scalar logical. it has no method endsWith().
% the correct syntax endsWith(f,pattern) doesn't make sense either
% because f is a scalar logical, not a string or char.
if f.endsWith([".jpg",".jpeg",".png", ".PNG"]) //problem is here
% again, append() doesn't work like that, and it doesn't work
% on logical scalars either. even if it did, this entire loop
% would accomplish nothing but disassembling the output from
% isfolder() and then reassembling it back into a logical vector.
image_files.append(f);
end
end
Are you trying to recursively search directories and build a list of paths to image files? What about image files that are not in a directory, but are specified directly in image_path?
采纳的回答
Adam Danz
2021-8-17
编辑:Adam Danz
2021-8-17
> I am trying to recursively search directories and build a list of paths to image files
Inputs:
% Define the main directory
image_path = 'C:\Users\name\Documents';
% list accepted extensions (with leading dot, case ignored)
acceptedExt = [".jpg",".jpeg",".png"];
Recursively search main directory (and sub directories) for files with listed extensions. fileList contains a cell array of full paths to matched files. The extension match ignores case.
d = dir(fullfile(image_path,'**\*.*'));
d([d.isdir]) = []; % remove directories from list
[~,ext] = regexp({d.name}','.*(\..*$)','match','once','tokens');
isAccepted = ismember(lower([ext{:}]), lower(acceptedExt));
d(~isAccepted) = []; % remove files that do not have accepted ext.
% list full paths to accepted files
fileList = fullfile({d.folder},{d.name})';
2 个评论
Adam Danz
2021-8-17
编辑:Adam Danz
2021-8-17
Sure, to display the number of accepted files for each extension, replace the ismember line with the line below and add the second block of code to the end.
[isAccepted,extIdx] = ismember(lower([ext{:}]), lower(acceptedExt));
% Count number of matches for each acceptedExt
unqExtIdx = unique(extIdx(isAccepted));
count = histcounts(extIdx(isAccepted), 'BinMethod','integers');
disp(compose('%s: %.0f', acceptedExt', count'))
Example output:
ans =
4×1 cell array
{'.jpg: 388'}
{'.jpeg: 0' }
{'.png: 0' }
{'.gif: 1' }
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!