Clicking on List to Plot

2 次查看(过去 30 天)
BACKGROUND: Below is the solution that Image Analyst(forum member) created by constructing two lists with variables and by clicking on the variable the data is output in the command window (see code below).
GOAL: My next step is to click on one variable on each list, and create a plot from the two variables that I selected.
CODE:
function learnlists
clc;
format compact;
format long;
figure;
yourcell={'mass','velocity','time','acceleration','speed'}
% Create first listbox.
uicontrol('Style', 'listbox','Position',[100 100 200 200],...
'string',yourcell,'Callback',@measurements)
% Create second listbox.
uicontrol('Style', 'listbox','Position',[300 100 200 200],...
'string',yourcell,'Callback',@measurements)
function [out] = measurements(handleToParentControl,evnt)
mass = [ 23 45 44];
velocity = [34 53 32];
time = [1 2 3];
acceleration = [32 22 12];
speed = [12 33 44];
selectedItem = get(handleToParentControl,'value');
% Print selected array to command window:
switch selectedItem
case 1
mass
case 2
velocity
case 3
time
case 4
acceleration
case 5
speed
end
  1 个评论
Walter Roberson
Walter Roberson 2013-5-30
hmmm.. thought you already asked this one a little earlier ?

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2013-5-30
I suggest that instead of having your measurements function as a callback, that you use something like
function [out] = measurements
mesnames = {'mass', 'velocity', 'time', 'acceleration', 'speed'};
mesvals = {[ 23 45 44], [34 53 32], [1 2 3], [32 22 12], [12 33 44]};
out = struct('name', mesnames, 'value', mesvals);
Then
handles.measurements = measurements();
handles.list1 = uicontrol('Style', 'listbox','Position',[100 100 200 200],...
'string',yourcell, 'Callback',@select_n_plot);
handles.list2 = uicontrol('Style', 'listbox','Position',[300 100 200 200],...
'string',yourcell, 'Callback', @select_n_plot);
guidata(gcf, handles);
function select_n_plot(hObject, event)
handles = guidata(hObject);
list1val = get(handles.list1,'Value');
list1var = handles.measurements(list1val);
list1varname = list1var.name;
list1varval = list1var.value;
and likewise for list2. After that, plot list1varval against list2varval and label with list1varname and list2varname

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by