フィルターのクリア

Clicking on List to Plot

1 回表示 (過去 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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by