how to fix Cell contents assignment to a non-cell array object.?
Show older comments
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 Comments
Cam Salzberger
on 20 Oct 2017
I'm not seeing an error when I do some basic reproduction steps. I'd recommend running the command "dbstop if error", then try your code again. This will cause the code to go into debug mode when the error is thrown. You'll be able to see what iteration is causing the error, and look at the sizes and data types of the left and right side of the assignment to see if you can spot the issue.
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
on 21 Oct 2017
Answers (0)
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!