Cell contents reference from a non-cell array object.

152 views (last 30 days)
clear all;
clc;
%For ceating nodes(Sensor node)
num1 = input('Enter the no of nodes you want to consider in your WSN');
radius = 30;
for i= 1:num1
X = rand(1,num1).*2;
Y = rand(1,num1).*3;
end
X
Y
%Calculate Distance
for i= 1:num1
for j= i+1 : num1
dist= sqrt((X{i}-X{j})^2+(Y{i}-Y{j})^2);
% C=dist(i,j);
end
end
disp(C)
I am getting error "Cell contents reference from a non-cell array object" for line dist= sqrt((X{i}-X{j})^2+(Y{i}-Y{j})^2);. Please tell me how to solve this problem.

Accepted Answer

Andrew Reibold
Andrew Reibold on 7 Oct 2014
Don't use the curly brackets. That tells Matlab its a cell when its not. It is an array. Write like this
dist= sqrt((X(i)-X(j))^2+(Y(i)-Y(j))^2);
  3 Comments
Regina N
Regina N on 11 Feb 2019
i also have same error in following code in line 13 plot...:
srcFiles = dir('C:\Users\LENOVO\Desktop\Genuine\1\*.png'); % the folder in which ur images exists
Features = cell(length(srcFiles),1) ;
Valid_points =cell(length(srcFiles),1) ;
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\LENOVO\Desktop\Genuine\1\',srcFiles(i).name);
I1 = rgb2gray(imread(filename));
points1 = detectSURFFeatures(I1); hold on;
[features1, interest_points] = extractFeatures(I1, points1);
Features{i} = features1 ;
Valid_points{i} = interest_points ;
figure; imshow(I1);
plot(interest_points{i}.selectStrongest(10),'showOrientation',true);
end
Features;
Valid_points;

Sign in to comment.

More Answers (2)

PATRICK WAYNE
PATRICK WAYNE on 14 Feb 2018
I've received this error using cell2mat. For instance, I'll have a P = 1 x 19 cell array where each cell holds a 600 x 1 double. Using
T = cell2mat(P)
works only when I run the entire m-file (giving me a 600 x 19 matrix). If I try to run it as a section in the code, I get the error. And, this line of code is NOT in any loop. I have no idea why this happens. It caused me to waste a LOT of hours.

priyanka
priyanka on 7 Oct 2014
Thank you.

Community Treasure Hunt

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

Start Hunting!

Translated by