Plots in one graph GUI evalin
Show older comments
Hello! I have a listbox and I would like that when I select several inputs in the listbox and click a button called "plot", the axes plots the variables I have selected. The variables could be "var1,2,3,4" but not var_p because it's fixed, it's the time. This is my code:
function [var_p,var1_p,var2_p,var3_p,var4_p] = get_var_names1(handles)
% Returns the names of the variables to plot_button1
global index_selected
list_entries = get(handles.listbox1,'String');
index_selected = get(handles.listbox1,'Value');
var_p = 'Temps';
var1_p =[];
var2_p =[];
var3_p =[];
var4_p =[];
if isempty(index_selected)
errordlg('You must select one variable','Incorrect Selection','modal')
else
%var = list_entries{index_selected(1)};
var1_p = list_entries{index_selected(1)};
var2_p = list_entries{index_selected(2)};
var3_p = list_entries{index_selected(3)};
var4_p = list_entries{index_selected(4)};
end
function plot_button1_Callback(hObject, eventdata, handles)
global index_selected
[x,y1,y2,y3,y4] = get_var_names1(handles);
if isempty(x) && isempty(y1)
return
end
axes(handles.axes1);
figure(gcf)
try
if index_selected==1 && index_selected==2 && index_selected==3 && index_selected==4
evalin('base',['plot(',x,',',y1,',',x,',',y2,',',x,',',y3,',',x,',',y4,')'])
datetick('x', 31, 'keepticks','keeplimits' ); %'keepticks' 'keeplimits'
xlabel('Date')
xticklabel_rotate; % calls file (available from matlab file exchange) that allows to display the label's ticks with a rotation of 45°
catch ex
errordlg(...
ex.getReport('basic'),'Error generating linear plot','modal')
end
This code kinda works but it means I have to do all the combinaisons like:
if index_selected==1
evalin('base',['plot(',x,',',y1,')]
if index_selected==1 && index_selected==2
evalin('base',['plot(',x,',',y1,',',x,',',y2,')])
ect... i have tried:
if index_selected==1
evalin('base',['plot(',x,',',y1,')'])
elseif index_selected==2
hold(handles.axes1)
evalin('base',['plot(',x,',',y2,')'])
elseif index_selected==3
evalin('base',['plot(',x,',',y3,')'])
elseif index_selected==4
evalin('base',['plot(',x,',',y4,')'])
hold off
end
but it doesnt work, gives me the error: Attempted to access index_selected(2); index out of bounds because numel(index_selected)=1.
Error in desk>get_var_names1 (line 348) var2_p = list_entries{index_selected(2)};
Error in desk>plot_button1_Callback (line 355) [x,y1,y2,y3,y4] = get_var_names1(handles);
I'm using R2013a. Can anyone help? Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Linear and Nonlinear Regression 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!