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)
