Hi there,
I am having some trouble with checking if a variable exists in the workspace. If the variable exists (which is a structure with time), it should plot the data in my GUI. If the variable does not exist, it should generate an error.
I used this code, however it will always generate an error even if the variable does exist in the workspace. I cannot find what I am doing wrong.
function AmechM_Callback(hObject, eventdata, handles)% Executes on button press in AmechM.
if exist('AmechM','var') AmechM = evalin('base','AmechM'); plot(AmechM.time,AmechM.signals.values); xlabel(handles.ax1,'time (s)'); ylabel(handles.ax1,'Acceleration (rad/s²)');else errordlg('The workspace does not contain any data. Run a simulation first.','Error');end
Best Answer