MATLAB: Cell contents reference from a non-cell array object.

getting error

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.

Best Answer

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);