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 :)
采纳的回答
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 个评论
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.
min([distAllTier1{i,:}]);
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 .
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
