Clear Filters
Clear Filters

How to add GUI for existing code

4 views (last 30 days)
Yihan Chen
Yihan Chen on 14 Dec 2018
Commented: Yihan Chen on 14 Dec 2018
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

Answers (1)

Jan
Jan on 14 Dec 2018
Edited: Jan on 14 Dec 2018
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 Comment
Yihan Chen
Yihan Chen on 14 Dec 2018
Thank you.I will try it on later tomorrow morning.

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!