필터 지우기
필터 지우기

Is it possible to have a switch case statement with the number of cases based on the length of a variable?

조회 수: 6 (최근 30일)
Hi
I am trying to build a GUI in MATLAB using GUIDE. I build up and store a database of household electrical appliances based on user inputs. I would like to create a pop-up menu which gives the user various options to display graphs of these appliances. Is it possible to make the number of options in the pop-up menu the same length as the number of appliances stored in the database bearing in mind the number of appliances is changeable. Your assistance on this matter would be much appreciated.
Thanks
Stuart

답변 (1개)

PT
PT 2013년 4월 10일
I am not aware there is any way to dynamically populate a switch statement. However, you can populate the popup menu during runtime.
Assuming some database structures:
Database = {
'television' 'television.mat'
'toaster' 'toaster.mat'
'refrigerator' 'refrigerator.mat'
'microwave' 'microwave.mat'
}
And in each mat file contains x and y variables for plotting.
In the Opening Function of the popup menu, you can do:
set(hObject, 'String', Database(:,1));
to populate the menu.
And in the Callback Function of the popup menu,
selected = get(hObject, 'Value');
load( Database(selected,2) );
plot( handles.axes1, x, y );
where axes1 is the tag for the plot box in your GUI.
  댓글 수: 3
Stuart
Stuart 2013년 4월 10일
That is ok no worries I will give this a go and see if I can get it to work.
Thanks

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

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by