필터 지우기
필터 지우기

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 CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by