how to fix Cell contents assignment to a non-cell array object.?

1 次查看(过去 30 天)
hallo I'm trying to create a 2D by N dimentions pictures features array to save code running time so i created the next code:
SurfFeatures = {};
folderlisting = dir('C:\Documents\');
for item=3:1:numel(folderlisting)
name = folderlisting(item).name;
Fname = strcat('C:\Documents\',name);
comperimg = imread(Fname);
comperimg = comperimg(:,:,1:3);
I = rgb2gray(comperimg);
points = detectSURFFeatures(I);
[features,valid_points] = extractFeatures(I,points);
SurfFeatures{item-2} = features;
end
save('SurfFeatures.mat','SurfFeatures');
I keep getting the next error right after the code enters the part of the feature assignment "Cell contents assignment to a non-cell array object."
happy for help :) .
  3 个评论
OCDER
OCDER 2017-10-20
编辑:OCDER 2017-10-20
I don't see anything wrong, but perhaps the error is in extractFeatures or detectSURFFeatures. Here are some tips to improve the code though.
FolderList = dir(fullfile('C:\Documents\', '*.jpg')); %Use file extensions since dir will also return "." and ".." folders, + other files
SurfFeatures = cell(1, numel(FolderList) - 2); %Preallocate for speed
for item = 3:numel(FolderList)
%name = FolderList(item).name; %Uppercase notation. Also, this isn't needed.
%Fname = strcat('C:\Documents\',name); %fullfile is better
%comperimg = imread(Fname);
%comperimg = comperimg(:,:,1:3); %squeeze will remove singleton dimension
Fname = fullfile('C:\Documents\',FolderList(item).name);
I = squeeze(imread(Fname));
I = rgb2gray(I);
Points = detectSURFFeatures(I);
[Features, ValidPoints] = extractFeatures(I, Points);
SurfFeatures{item-2} = Features;
end
save('SurfFeatures.mat','SurfFeatures');
Be consistent when using camelcase notation to help you determine what is a function vs variable. I noticed a partial implementation, which can get confusing later (ex: valid_points vs ValidPoints). Using uppercase is generally good for variables, to prevent overriding a matlab function by accident. You're function naming scheme is fine
noam Y
noam Y 2017-10-21
thanks a lot that fixed it. but why because I didn't assign it first to be a cell array?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by