Matlab error for "Assignment has more non-singleton rhs dimensions than non-singleton subscripts".

Hi, i have error of "Assignment has more non-singleton rhs dimensions than non-singleton subscripts".
Error in Untitled10 (line 205)
distAllTier1(i,j)= sqrt((node(i).x - node(j).x).^2 + (node(i).y - node(j).y).^2);
The details code as follow:
for i = 1:1:numNodes
for j = indPCHTier1
if node(i).tier == 1
if i == j
distAllTier1(i,j) = NaN;
else
distAllTier1(i,j)= sqrt((node(i).x - node(j).x).^2 + (node(i).y - node(j).y).^2);
end
else
distAllTier1(i,j) = NaN;
break;
end
end
end
The result for
sqrt((node(i).x - node(j).x).^2 + (node(i).y - node(j).y).^2);
is:
ans =
10.295630140987001
21.213203435596427
Then the "distAllTier1(i,j)" cannot support the value. How can i solve this problem?
Thanks :)

 Akzeptierte Antwort

sqrt((node(i).x - node(j).x).^2 + (node(i).y - node(j).y).^2);
The output of above is 2*1..and you are trying to save output into a single scalar..
distAllTier1(i,j)
so the error is popping out. I think the output of sqrt() should be a scalar. Show us the complete code to get more help.

14 Kommentare

Yes, correct. How can i change the input "distAllTier1(i,j)" into multi scalar?
I try to make like this, distAllTier1(i,j:2) but it doest not work.
The complete code is almost 500++ line, this problem came out because i change the matrix as my previous question in --> here
I attach again the related code:
numPCHTier1 = 0;
for i = 1:1:numNodes
if node(i).pch == 1 && node(i).tier == 1
numPCHTier1 = numPCHTier1 + 1;
indPCHTier1(1,numPCHTier1) = i;
end
end
distAllTier1 = zeros(numNodes,numPCHTier1);
for i = 1:1:numNodes
for j = indPCHTier1
if node(i).tier == 1
if i == j
distAllTier1(i,j) = NaN;
else
distAllTier1(i,j)= sqrt((node(i).x - node(j).x).^2 + (node(i).y - node(j).y).^2);
end
else
distAllTier1(i,j) = NaN;
break;
end
end
end
Try using cells...
distAllTier1 = cell(numNodes,indPCHTier1) ;
count = 0 ;
for i = 1:1:numNodes
for j = indPCHTier1
count = count+1 ;
if node(i).tier == 1
if i == j
distAllTier1{i,j} = NaN;
else
distAllTier1{i,j}= sqrt((node(i).x - node(j).x).^2 + (node(i).y - node(j).y).^2);
end
else
distAllTier1{i,j} = NaN;
break;
end
end
end
Thanks @KSSV for your help, when change to cell it appear error like this:
Error using cell
Size inputs must be scalar.
There was a typo error..now modified...check it now.
WOW! you are so fantastic! Thanks it works!
However, i change the line to this:
distAllTier1 = cell(numNodes,numPCHTier1) ;
Thanks
I'm sorry sir, regarding for changing into cell, i got an issues here :
distAllTier1(distAllTier1 == 0) = NaN;
Above line appear some error:
Undefined operator '==' for input arguments of type 'cell'.
I try to change ( ) to { }, its still same.
Thanks
You cannot use cells like that. See this:
k{1} = [1 0] ;
idx = k{1}==0 ;
k{1}(idx) = NaN
Then i change k into distAllTier1. Thanks sir!
Sir, one more sir.
for i = 1:1:noTier1
if node(i).pch ~= 1
[minVal,index] = min(distAllTier1(i,:));
node(i).head = index;
end
end
It contain error:
Undefined function 'min' for input arguments of type 'cell'.
Error in Untitled10 (line 267)
[minVal,index] = min(distAllTier1(i,:));
The cell cannot read min value. Again i try to use { } but Matlab said,
Error using min
Too many input arguments.
I hope u can help me for last time. Thanks Dr.
I try to find the solution, but could not solve it. After do min([distAllTier1{i,:}]); it appear this error:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in Untitled10 (line 267)
[minVal,index] = min([distAllTier1{i,:} ] );
[distAllTier1{i,:}]
Try the above line alone.....this should give you a vector.
Thanks sir, i appreciate your time and help .

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by