Cell contents reference from a non-cell array object.

53 ビュー (過去 30 日間)
priyanka
priyanka 2014 年 10 月 7 日
コメント済み: Regina N 2019 年 2 月 11 日
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 件のコメント
muhammad illyas abdul muhji
muhammad illyas abdul muhji 2018 年 4 月 23 日
does it work for image processing as well?
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 Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by