フィルターのクリア

How to add GUI for existing code

4 ビュー (過去 30 日間)
Yihan Chen
Yihan Chen 2018 年 12 月 14 日
コメント済み: Yihan Chen 2018 年 12 月 14 日
Hi everyone,
I have a written code of vibration shape mode. Since there are too many curves in my plot, I'm thinking about using popup menu to organize them. However, I don't know how to make it work after I created my GUI. I've tried to put my entire code into the callback of popupmenu function but it didn't work. Here's how I'm plotting it right now. I want to make the corresponding plot everytime I pick a k value from the popup menu. Can someone help me with it?
%Assign each interior displacement to its location
figure(1)
for k=1:s_e%looping over frequencies
for i=1:n%looping over elements
%Plot 14.4c elemental displacement
plot(l(i,:),vd{k}(i,:),'-x')
hold on
grid on
plot(l_b,vd_b,'-ko')%Original beam plot
end
title('Vibration mode shape with 4 elements')
%Show max displacement point for each graph
MaxVd{k}=max(max(vd{k}));
indexofMax=find(vd{k}==MaxVd{k},1,'first');
maxY=vd{k}(indexofMax);
maxX=l(indexofMax);
plot(maxX,maxY,'-k^');
text(maxX,maxY,['(' num2str(maxX) ',' num2str(maxY) ')'],'HorizontalAlignment','right','FontSize',7);
end
hold off

回答 (1 件)

Jan
Jan 2018 年 12 月 14 日
編集済み: Jan 2018 年 12 月 14 日
figure;
axes('NextPlot', 'add'); % same as "hold on"
grid on % Once only!
plot(l_b,vd_b,'-ko') % Once only! Original beam plot
HandleList = cell(1, s_e);
for k=1:s_e % looping over frequencies
H = gobjects(1, n + 2);
for i=1:n % looping over elements
%Plot 14.4c elemental displacement
H(i) = plot(l(i,:),vd{k}(i,:),'-x')
end
title('Vibration mode shape with 4 elements')
%Show max displacement point for each graph
MaxVd{k}=max(max(vd{k}));
indexofMax=find(vd{k}==MaxVd{k},1,'first');
maxY=vd{k}(indexofMax);
maxX=l(indexofMax);
H(n+1) = plot(maxX,maxY,'-k^');
H(n+2) = text(maxX,maxY,['(' num2str(maxX) ',' num2str(maxY) ')'], ...
'HorizontalAlignment','right','FontSize',7);
HandleList{k} = H;
end
allHandle = cat(2, HandleList{:});
set(allHandle, 'Visible', 'off')
Then provide HandleList as input of the callback of the popup menu:
uicontrol('Style', 'popup', 'String', sprintfc('%d', 1:s_e), ...
'Callback', {@myPopupCB, HandleList}, ...
'Position', [5, 5, 80, 22]);
And the callback:
function myPopupCB(PopupH, EventData, HandleList)
value = get(PopupH, 'Value');
for k = 1:numel(HandleList)
if ismember(k, value)
set(HandleList{k}, 'Visible', 'on');
else
set(HandleList{k}, 'Visible', 'off');
end
end
drawnow;
end
  1 件のコメント
Yihan Chen
Yihan Chen 2018 年 12 月 14 日
Thank you.I will try it on later tomorrow morning.

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

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by