Unable to perform assignment with 0 elements on the right-hand side.

75 ビュー (過去 30 日間)
Alexandra Philip
Alexandra Philip 2020 年 7 月 20 日
コメント済み: Image Analyst 2020 年 7 月 21 日
I am having some error with obtain a variable that contain a value from the table with the conditions that th AccelSNEditField input equals on of the values in the first column and to use that row and look at the 2nd column of the table to obtain the value for that variable:
BIA0=mergetables{app.AccelSNEditField == mergetables{:,1},2};
However, I am obtaining this error:
Unable to perform assignment with 0 elements on the right-hand side.
Any suggestions or resolutions?

回答 (2 件)

Stephen23
Stephen23 2020 年 7 月 20 日
編集済み: Stephen23 2020 年 7 月 20 日
The actual problem is that you think that one (or more) of these values match:
app.AccelSNEditField == mergetables{:,1}
In fact they don't. Zero matches. None. Zilch. Nada.
And then you construct a comma-separated list with zero arrays in it and try to allocate those zero arrays to one array.
Does not compute. Not possible. No can do. Il n'est pas possible.
Solution:
That depends on what the problem is. I can see two main possibilities:
  1. Are matches known to exist? Then perhaps your data is not correct (e.g. missing data, wrong units, etc.), or the matching needs to take into account floating point error (e.g. compare absolute difference against a toleance), or throw an error as this indicates an obvious bug in the input data.
  2. Perhaps for some values no matches actually exist, in which case you need to add special-case handling to your code.

Image Analyst
Image Analyst 2020 年 7 月 20 日
app.AccelSNEditField == mergetables{:,1}
is going to product a vector of true or false values, which evaluate to 1 or 0 when used as a numerical index. Evidently some of your comparisons are false, which evaluate to zero. There is no zero index for arrays. You can have the first row, but you cannot have the zeroeth row. In this matrix
m = [1, 2;
3, 4];
The first row is [1, 2], but what is the zeroeth row? There is no zeroeth row. See the FAQ for a thorough discussion:
  8 件のコメント
Alexandra Philip
Alexandra Philip 2020 年 7 月 20 日
I converted the mergetables to a table and now the braces work.
However the output now for BIA0 is:
BIA0 =
0×1 empty double column vector
And it should be a numeric value.
Image Analyst
Image Analyst 2020 年 7 月 21 日
Well we're back to having no matches in the comparison:
app.AccelSNEditField == mergetables{:,1}
when you do this:
BIA0=mergetables{app.AccelSNEditField == mergetables{:,1},2};
It's hard to help when we don't have all the variables. Can you attach them in a .mat file:
AccelSNEditField = app.AccelSNEditField;
save('answers.mat', 'AccelSNEditField', 'mergetables');
Then attach answers.mat with the paper clip icon.

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by