Clicking on List to Plot

4 Ansichten (letzte 30 Tage)
Amanda
Amanda am 30 Mai 2013
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 Kommentar
Walter Roberson
Walter Roberson am 30 Mai 2013
hmmm.. thought you already asked this one a little earlier ?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 30 Mai 2013
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
  1 Kommentar
Amanda
Amanda am 30 Mai 2013
I've been on this problem all day. Thanks.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by