- 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.
- Perhaps for some values no matches actually exist, in which case you need to add special-case handling to your code.
Unable to perform assignment with 0 elements on the right-hand side.
41 views (last 30 days)
Show older comments
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?
0 Comments
Answers (2)
Stephen23
on 20 Jul 2020
Edited: Stephen23
on 20 Jul 2020
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:
0 Comments
Image Analyst
on 20 Jul 2020
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 Comments
Image Analyst
on 21 Jul 2020
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.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!