Error Insufficient number of outputs from right hand side of equal sign to satisfy assignment

9 Ansichten (letzte 30 Tage)
Hi guys,
unfortunately I have an strange issue...
I implemented a ROS Subscriber with Robotics System Toolbox and everything works fine... But when I'm trying to assign a value from the subscribed topic like this...:
bla = info_sub.LatestMessage.ANGLEIST
there always comes the error "Insufficient number of outputs from right hand side of equal sign to satisfy assignment".
Everything's ok with the message ANGLEIST I'm able to see the value when I just type "info_sub.LatestMessage.ANGLEIST". Most strange thing is that the assignment bla = info_sub.LatestMessage.ANGLEIST works fine in commandline !! Just the assignment out of the m-File doesn't work for some reason.
What is the reason for that behaviour?
Best Regards, Marvin
  5 Kommentare
Tim Rodrigues
Tim Rodrigues am 27 Jul. 2016
One possibility you may have thought of: Does the variable "bla" get used elsewhere in the program? if bla has been sized previously as a variable with more dimensions or a structure with more fields than are being generated by your right hand side " info_sub.LatestMessage.ANGLEIST" then one could get an error like this.
If this is the case, one could set bla = 0; or clear bla before the assignment statement
An example: >> h=figure(1); >> h.Name=sin(1:10); While setting the 'Name' property of 'Figure': Value must be a string.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Steven Lord
Steven Lord am 27 Jul. 2016
I did a search in the Robotics System Toolbox documentation. I was able to find information about the LatestMessage property of some of the objects, but I didn't find any information about ANGLEIST.
But I believe I know what's going on. I'll demonstrate with a simpler example, one that just uses a struct.
>> S = struct('x', 5);
>> S = S(zeros(1, 0));
>> b = S.x;
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
If you look at S after the second line, it is a 1x0 struct array. It still has a field named x, but there's no data associated with that because S is empty. So if you ask for S.x that returns nothing. You've essentially created a comma-separated list with no list elements. So when MATLAB tries to execute the third line, it's trying to assign nothing (on the right) to a variable on the left and that causes the error you received. There are three ways I can think of offhand for you to handle this scenario.
The first is to check before asking for the ANGLEIST property of the object stored in the LatestMessage property if it is empty using isempty. If so, there WAS no LatestMessage and you'll need to handle that scenario.
if isempty(info_sub.LatestMessage)
b = some_default_value;
% or error('LatestMessage should not have been empty!')
else
b = ...
end
The second is to poll in a loop, waiting until LatestMessage is nonempty to retrieve the value. Here I have to switch examples to something I can affect even while MATLAB is waiting in a while loop.
>> h = plot(1:10);
>> while ~isequal(h.Color, [1 0 0])
drawnow
end
This will pause execution until I change the properties of the line (via the Plot Tools) to red. Your while condition would be to check that LatestMessage is nonempty. [There may be a specific function in Robotics System Toolbox to perform this polling more elegantly; I'm not familiar with that toolbox, though.]
The third approach is to store the value you retrieved and some "placeholder" value in a cell array.
>> b = {S.x, NaN}
If S.x is empty, as it is in this case, b will be the 1x1 cell array whose only cell is NaN. If it isn't empty:
>> S = struct('x', 5);
>> b = {S.x, NaN}
the first cell of b will contain your data, and the second will contain your "placeholder". This will mean one more indexing operation, to retrieve the contents in the first cell of b, but it will guard against the scenario where there was no LatestMessage.
As for why this worked when you tried it at the Command Window prompt, or in debug mode, my guess is that by the time you ran this in the Command Window or in debug mode, a message had arrived and so LatestMessage was nonempty. In that case, everything works just fine.
  4 Kommentare
Marvin Schöner
Marvin Schöner am 15 Aug. 2016
Again sorry for delay in answer, went to vacation last week..
I tried the first of your explained ways and it worked fine!
Thank you so much for your support!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Network Connection and Exploration finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by