フィルターのクリア

switch function case{name}

3 ビュー (過去 30 日間)
Abdulaziz
Abdulaziz 2012 年 11 月 20 日
Hi folk, Please, is there any way to give a case a name instead of number and then call the case by clicking its name on command window. I mean showing all the cases name on the command window ( like an active name) so when we click on it, it will be input, all this to avoid typing the case name.
Material=input(Please Enter ...) switch Material case{name1}.... case{2}.... case{3}.... end

回答 (3 件)

Walter Roberson
Walter Roberson 2012 年 11 月 20 日
  1 件のコメント
Abdulaziz
Abdulaziz 2012 年 11 月 25 日
Thank you Walter for the link you attached

サインインしてコメントする。


Harshit
Harshit 2012 年 11 月 20 日
Here is an example from mathworks
% x = [12, 64, 24];
plottype = 'pie3';
switch plottype
case 'bar'
bar(x)
title('Bar Graph')
case {'pie','pie3'}
pie3(x)
title('Pie Chart')
legend('First','Second','Third')
otherwise
warning('Unexpected plot type. No plot created.');
end
  2 件のコメント
Harshit
Harshit 2012 年 11 月 20 日
Abdulaziz
Abdulaziz 2012 年 11 月 25 日
Thanks Harshit

サインインしてコメントする。


Matt Fig
Matt Fig 2012 年 11 月 20 日
編集済み: Matt Fig 2012 年 11 月 20 日
This might be a case where a little pushbutton input GUI would be of service. For exmaple, save this as gui_input then call it like this (you can pass only 2, 3, 4 or any number of strings):
T = gui_input({'Iron';'Copper';'Steel';'Lead';'Oxygen'})
Here is the function:
function [C] = gui_input(C)
% How to get inputs from pushbuttons.
S.fh = figure('name','Choose a Material',...
'menubar','none',...
'numbert','off',...
'pos',[100 100 300 300]);
LC = numel(C);
H = (300 - (LC+1)*20)/LC;
P = [10 10 280 H];
for ii = 1:LC
uicontrol('Style','push',...
'Units','pix',...
'Position',P + [0 (ii-1)*(H+20) 0 0],...
'CallBack',@callb,...
'String',C{ii});
end
movegui('center')
guidata(S.fh,S)
uiwait(S.fh)
try
S = guidata(S.fh);
C = S.C;
close(S.fh)
catch
C = [];
end
function [] = callb(varargin)
% Callback for the edit box 1
S = guidata(gcbf); % Get the structure.
S.C = get(gcbo,'string');
guidata(S.fh,S)
uiresume(S.fh)
  2 件のコメント
Abdulaziz
Abdulaziz 2012 年 11 月 25 日
Thank you Matt. I tried to use gui_input with switch function where i have 5 materials (5 cases) but i still can not make it works
Jan
Jan 2012 年 11 月 25 日
@Abdulaziz: Please explain the occurring problems with any details. We cannot suggest an improvement based on "cannot make it working".

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by