How to draw an uncertain number of sub-images in one coordinate in app designer?
3 views (last 30 days)
Show older comments
I can use matlab script to draw VMD decomposition diagram, but I don't know how to draw such a diagram in one coordinate in app designer? Below is the code in my matlab script and the picture I need to draw. Thank you very much for your time.
[m,n]=size(u);
figure
subplot(m+1,1,1);
plot(DATA.data,'k');grid on;
title('Original data');
for i = 1:m
subplot(m+1,1,i+1);
plot(u(i,:),'k');
title(['Signal',num2str(i-1),':']);
end
1 Comment
Benjamin Kraus
on 4 Jun 2024
Can you clarify what you mean by "one coordinate" in the sentence "I don't know how to draw such a diagram in one coordinate in app designer"?
Answers (2)
Benjamin Kraus
on 4 Jun 2024
Edited: Benjamin Kraus
on 4 Jun 2024
I'm not sure what you mean by "one coordinate", but the way I would create the diagram above in App Designer would be:
- When designing your app, drag and drop a panel into the location in your app in which you want to draw the diagram.
- Within your code (either your startup function or any other callback of your app), create a tiledlayout with a vertical layout.
- Add as many axes as you want to the layout using the nexttile command and plot into those axes.
For example, assuming you have a handle to your panel named app.UIPanel:
% This code is written automatically when you drag and drop a panel into your app.
app.UIPanel = uipanel;
% This code needs to be added to a callback function of your app.
tcl = tiledlayout(app.UIPanel, 'vertical');
% This code creates a number of different axes and plots into them.
m = 5;
for i = 1:m
ax = nexttile(tcl);
plot(ax, 1:10, sin(1:10),'k');
title(ax, ['Signal ',num2str(i-1)]);
end
5 Comments
Benjamin Kraus
on 5 Jun 2024
@Xiangfeng: As the error states, that indicates that your axes (stored in the variable ax) has been deleted.
Based on the code I can see, I suspect the issue is that your calls to subplot are deleting axes.
The subplot command will delete any axes that overlap with the axes you are trying to create. You are calling subplot in a loop, and appending new values to a vector of axes handles stored in the variable ax. You are also calling subplot twice each loop. My guess is that a later call to subplot is deleting an axes created in an earlier call to subplot, so that when you call xticklabels one of the elements in the vector has been deleted.
I suspect the first fix you want to apply is to index into ax when you call xticklabels:
xticklabels(ax(i+1), [])
See Also
Categories
Find more on Labels and Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!