lists generated by uicontrol

조회 수: 1 (최근 30일)
Amanda
Amanda 2013년 5월 29일
I have the following data:
mass = [ 23 45 44]
velocity = [34 53 32]
time = [1 2 3]
acceleration = [32 22 12]
speed = [12 33 44]
What I'm trying to achieve is to apply uicontrol that creates two lists with this data (mass, velocity, time, acceleration, speed), and have the ability to click on one of the variables (mass) in each column and there is a numerical data output, like mass = 23 45 44
Output: numerical data stored in these variables
Here is the code:
function learnlists()
figure;
yourcell={'mass','velocity','time','acceleration','speed'}
hb = uicontrol('Style', 'listbox','Position',[100 100 200 200],...
'string',yourcell,'Callback',@measurements)
yourcell={'mass','velocity','time','acceleration','speed'}
hc = uicontrol('Style', 'listbox','Position',[300 100 200 200],...
'string',yourcell,'Callback',@measurements)
function [out] = measurements(hb,evnt)
outvalue = get(hb,'value');
v = get(hb,'value')
if v == 1
mass = [1 2 3 4 5]
elseif v == 2
velocity = [ 1 2 3 4 5]
end
end
end
Thanks,
Amanda

채택된 답변

Image Analyst
Image Analyst 2013년 5월 29일
Do you mean like this:
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
Amanda
Amanda 2013년 5월 29일
Thanks a lot! This is it.

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

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