How to add GUI for existing code
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!