How do I transfer my plots from Simulink scopes to a GUI.

2 views (last 30 days)
Hello, I am new to Matlab and am trying to transfer my plots from Simulink scopes to a GUI. I have a scope in Simulink that has 4 subplots in it. My plot pushbutton is not working when I press it. I keep getting the error: ??? Error using ==> plot Vectors must be the same lengths.
Error in ==> f14ex>PlotButton_Callback at 284 pHandles = plot(PlotData{:},'Parent',handles.PlotAxes);
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> f14ex at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)f14ex('PlotButton_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
This is my code:
function PlotButton_Callback(hObject, eventdata, handles)
% hObject handle to PlotButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Callback of the uicontrol handles.PlotButton.
currentVal = get(handles.ResultsList,'Value');
% Get data to plot
legendStr = cell(length(currentVal),1);
plotColor = {'b','g','r','c','m','y','k'};
for ctVal = 1:length(currentVal);
PlotData{(ctVal*3)-2} = handles.ResultsData(currentVal(ctVal)).timeVector;
PlotData{(ctVal*3)-1} = handles.ResultsData(currentVal(ctVal)).outputVector;
numColor = ctVal - 7*( floor((ctVal-1)/7) );
PlotData{ctVal*3} = plotColor{numColor};
legendStr{ctVal} = [handles.ResultsData(currentVal(ctVal)).RunName,'; Speed=', ... num2str(handles.ResultsData(currentVal(ctVal)).SpeedValue)];
end
% If necessary, create the plot figure and store in handles structure
if ~isfield(handles,'PlotFigure') ~ishandle(handles.PlotFigure),
handles.PlotFigure = figure('Name','simpleModel Simulation Output','Visible','off',...
'NumberTitle','off','HandleVisibility','off','IntegerHandle','off');
handles.PlotAxes = axes('Parent',handles.PlotFigure);
guidata(hObject,handles)
end
% Plot data
pHandles = plot(PlotData{:},'Parent',handles.PlotAxes);
% Add a legend, and bring figure to the front
legend(pHandles(1:2:end),legendStr{:})
% Make the figure visible and bring it forward
figure(handles.PlotFigure)
%endfunction PlotButton_Callback

Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!