Error “Assignment has more non-singleton rhs dimensions than non-singleton subscripts”?

Why do I get the error “Assignment has more non-singleton rhs dimensions than non-singleton subscripts”?

3 件のコメント

I am getting this error: can you help me please.
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
X(:,n) = Y*X(:,n-1) + Z*Vm;
pratik patel:
Please show us
size(X)
size(Y)
size(Z)
size(Vm)
I suspect that you have created either Z or Vm as global variables and failed to initialize them, which would leave them as empty, resulting in an empty right hand side.
Anshu Khare
Anshu Khare 2021 年 1 月 25 日
bankans(i,:)=sum(bsxfun(@times, ft(i,:), H).^2,2);
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
i am getting this error.please help me

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2013 年 10 月 23 日
編集済み: MathWorks Support Team 2018 年 11 月 27 日
In R2017b and earlier releases, this error occurs when you try to assign to a variable, but the indices of the left- and right-hand side of the assignment are incompatible. For example,
A(1) = [1 2 3];
throws this error because the size of the left-hand side is 1-by-1, but the size of the right-hand side is 1-by-3.
In R2018a and later, there is a new error message that replaces this error:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
For more information on matrix indexing, see:

3 件のコメント

Jan Andrzejewski
Jan Andrzejewski 2016 年 7 月 18 日
編集済み: Jan Andrzejewski 2016 年 7 月 18 日
You use "right hand size" and "right hand side" interchangeably.. it could lead to mistake.
Greetings
Adam
Adam 2016 年 7 月 18 日
I imagine it is just a typo.
Walter Roberson
Walter Roberson 2016 年 7 月 18 日
Yes, it was just a typo.

サインインしてコメントする。

その他の回答 (1 件)

CHANDRA
CHANDRA 2016 年 8 月 29 日

2 投票

what is the possible solution for this error

3 件のコメント

The solution is not to store more dimensions of source data than you have available dimensions of destination locations.
The error message will have pointed out the exact line with the problem. From there use size() of the various variables to figure out which dimension(s) has the mismatch of expectations. After that, rewrite the code so that it only selects as many dimensions of source data as you have available to write to, or else rewrite the code so that you make more destination locations available.
One of the common patterns to this problem is that new programmers tend to write loops in which they think they are selecting one element of a vector at a time, but they forget to subscript the vector somewhere in the loop, leading to it meaning "the entire vector" at that point. For example,
for K = 1 : 10
y(K) = 5 * x(K).^2 - 3 * x + 2;
end
Here the first reference to x has properly selected just one element of the vector, but the second reference, the 3 * x, forgot to select just one element. The corrected version of the above would be
for K = 1 : 10
y(K) = 5 * x(K).^2 - 3 * x(K) + 2;
end
math man
math man 2017 年 9 月 6 日
編集済み: Walter Roberson 2017 年 9 月 7 日
I am getting the same error. But very curiously, if I go to the offending line (with a stop in the debugger), then press play, the error does not occur.
Here is some of the error/code:
Error in RealTime_SpreadOverWrite (line 11)
MainObject.MarketData(Row,SpreadBaseCol)=ViggedProbMat(Row,TextFind('SpreadBase1',RawMarketLabels))*SpreadSignMult;
The relevant values for the operation are all real-scalars which I can see are present when I put a stop before executing this line.
Puzzling- what code can I show to help solve this? Thanks!!
Greg Coyle
Greg Coyle 2017 年 12 月 24 日
Great answer, Walter, thank you. I'd been checking length rather than size and all I needed to do was throw a transpose operator on one variable. Solved!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2013 年 10 月 23 日

コメント済み:

2021 年 1 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by