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

1 回表示 (過去 30 日間)
noam Y
noam Y 2017 年 10 月 20 日
コメント済み: noam Y 2017 年 10 月 21 日
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 Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by