Clicking on List to Plot

조회 수: 4 (최근 30일)
Amanda
Amanda 2013년 5월 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
  댓글 수: 1
Amanda
Amanda 2013년 5월 30일
I've been on this problem all day. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (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