Cell contents reference from a non-cell array object.

53 次查看(过去 30 天)
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.

采纳的回答

Andrew Reibold
Andrew Reibold 2014-10-7
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 个评论
Regina N
Regina N 2019-2-11
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;

请先登录,再进行评论。

更多回答(2 个)

PATRICK WAYNE
PATRICK WAYNE 2018-2-14
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 2014-10-7
Thank you.

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by