Skip to content

Cell Contents Assignment To A Non-Cell Array Object Matlab Error

Maybe this might help:

function Apply_Callback(hObject, eventdata, handles) global I

data = importdata('LDA data.mat')

features=data(:,1:end-1); %split data without labels

lable = data(:,end); %get the labels from training data

trainSamples = features;%training samples

trainClasses = lable;%training labels

I2 = reshape(I,[],1);

testSamples = I2;%test samples

lableimage = reshape(handles.lableimage,[],1);

testClasses = lableimage;%test labels

mLDA = LDA(trainSamples, trainClasses);


transformedTrainSamples = mLDA.Transform(trainSamples, 1);

transformedTestSamples = mLDA.Transform(testSamples, 1);

calculatedClases = knnclassify(transformedTestSamples,

transformedTrainSamples, trainClasses);

simmilarity = [];

for i = 1 : 1 : length(testClasses)

similarity(i) = ( testClasses{i} == calculatedClases{i} );


accuracy = sum(similarity) / length(testClasses);

fprintf('Testing: Accuracy is: %f %%\n', accuracy*100);

guidata(hObject, handles);

% hObject handle to Apply (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

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