MATLAB Answers

Error: One or more outputs not assigned during call to set

20 views (last 30 days)
Mubashir Irfan
Mubashir Irfan on 17 Apr 2016
Commented: Image Analyst on 17 Apr 2016
Hi. I am making a basic program related to e-voting, but I am facing this issue. When I run the following piece of code, I get error
Code :
username = get(handles.userid,'String');
[~,~,voterslist] = xlsread('C:\Users\Kausar Nigar\Desktop\E-Vote\Voters List.xlsx');
decider = find(strcmp(voterslist(:,:),username),1)
if (decider == 1)
{
set(handles.homeimage,'Visible','off')
set(handles.votepanel,'visible','on')
set(handles.login,'visible','off')
set(handles.logintext,'visible','off')
set(handles.partysigns,'visible','on')
}
else msgbox('Dear User, this ID is not registered. Please recheck the username or contact the Administrator.');
end
Error:
??? One or more output arguments not assigned during call to "set".
Error in ==> untitled>login_Callback at 114
set(handles.homeimage,'Visible','off')
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> untitled at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)untitled('login_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 17 Apr 2016
In MATLAB, {} designates cell array building, so when you have
{
set(handles.homeimage,'Visible','off')
set(handles.votepanel,'visible','on')
}
it means that you want to build a cell array whose first value is whatever is returned by set(handles.homeimage,'Visible','off') and whose second value is whatever is returned by set(handles.votepanel,'visible','on') . This requires that set() be able to return a value, but set() cannot return a value at all (not in that form of set()).
MATLAB is not C or C++. MATLAB does not use {} to group code.

  3 Comments

Image Analyst
Image Analyst on 17 Apr 2016
To fix, get rid of the { (opening brace) and replace the } (closing brace) by the word "end".
Mubashir Irfan
Mubashir Irfan on 17 Apr 2016
Thanks that helped. But one more problem now, it is not turning off the visibility of an image (tag homeimage) and the editable text box (tag logintext). What do I do now?
Image Analyst
Image Analyst on 17 Apr 2016
The visibility of the edit field should be settable. For the image, I believe you have to put the whole axes inside a panel, and set the panel visibility. Or see the code below:
% Sets visibility of an image that is displayed in an axes.
% Let's say you've used imshow() to display an image in an axes.
% Now, let's say you want to hide that image.
% For some reason, when you set the visibility of the axes (which is a
% containter for the image) to 'off', the image does not disappear. All
% this does is to make the lines, tick marks, and labels for the graph in
% the axes (which actually don't even appear when you're showing an image)
% disappear, but it leaves the image still visible. The "reason" for this
% is that the image is a child of the axes and when you set visibility of
% the parent container to be false, it does not set the visibility of all
% the things it contains to also be false. You have to do that manually,
% which is what this function does.
% MATLAB proves itself, once again, to be very quirky.
% visibility argument = 1 or 0 for visible or invisible.
% Image Analyst
function allHandles = SetImageVisibility(handles, axesHandle, visibility)
% Get the handles of all the things in the axes, including the axes itself.
allHandles = findobj(axesHandle);
% Loop through all objects, setting their visibility to the specified value.
for k = 1 : size(allHandles)
hChild = allHandles(k);
objectType = get(hChild,'type');
if visibility == 1 && (strcmpi(objectType, 'axes') <= 0)
% Set visible unless it's the axes themselves.
% Keep the axes themselves always turned off, just set visible
% the things inside of the axes container.
set(hChild, 'visible', 'on');
else
set(hChild, 'visible', 'off');
end
end
return;

Sign in to comment.