필터 지우기
필터 지우기

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

조회 수: 54 (최근 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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by