I'm trying to subplot 2 graphs in the same figure but I'm only getting the first graph. Need help trying to display both graphs
figure;
subplot(2, 1, 1)
plot(frames, Knee_A(:, 1), 'ro-', 'linewidth', 2); hold on;
plot(frames, Knee_A(:, 2), 'go-', 'linewidth', 2);
plot(frames, Knee_A(:, 3), 'bo-', 'linewidth', 2);
xlabel('Fluoroscopic Frame (30 FPS)');
ylabel('Angle (deg)');
legend('Flex/EXT', 'ADD/ABD', 'IR/ER', -1);
title([handles.SubjectName, ' ', handles.SubjectSide, ' ', handles.TrialName, ' Knee Angles']);
subplot(2, 1, 2)
plot(frames, Knee_V_tibia(:, 1), 'ro-', 'linewidth', 2); hold on;
plot(frames, Knee_V_tibia(:, 2), 'go-', 'linewidth', 2);
plot(frames, Knee_V_tibia(:, 3), 'bo-', 'linewidth', 2);
xlabel('Fluoroscopic Frames (30 FPS)');
ylabel('Translation (mm)');
% plot(frames, sum(StemV_cup.^2, 2).^.5, 'ko-', 'linewidth', 2);
title('Knee Translations')
legend('A/P', 'P/D', 'L/M', -1);

1 commentaire

Adam Danz
Adam Danz le 5 Août 2022
Modifié(e) : Adam Danz le 5 Août 2022
Does anything show up where the second subplot should be? An empty axes?
Screenshot of the figure might be helpful, or attaching the data. Knee_V_tibia might be all NaNs or empty.

Connectez-vous pour commenter.

 Réponse acceptée

Jon
Jon le 5 Août 2022
Modifié(e) : Jon le 5 Août 2022
The problem is that you have an error in your line
Error using legend
Invalid argument. Type 'help legend' for more information.
Error in missingplot (line 11)
legend('Flex/EXT', 'ADD/ABD', 'IR/ER', -1);
Specifically the -1 at the end is not correct. So the script crashes before it ever makes the second subplot.
Note the line number this occurs in for your code is probably not 11, I added a few lines ahead of your script to make up some data. Anyhow, it is the line that has the legend command. Same thing for legend in second subplot

5 commentaires

Jon
Jon le 5 Août 2022
Also obviously your script is not called missingplot, that is just what I called my script that I saved using your code in order to debug it.
Adam Danz
Adam Danz le 5 Août 2022
@Jon good catch.
@Pete Tuchinda: Lesson learned - pay attention to error messages and always include the full copy-pasted error message in your question.
Walter Roberson
Walter Roberson le 5 Août 2022
numbers as the final parameter to legend() used to indicate the plot position. I think -1 corresponded to the current "best" request
So using current MATLAB versions (R2022a)
legend('Flex/EXT', 'ADD/ABD', 'IR/ER','Location','best');
PT
PT le 6 Août 2022
@Jon Thank you! Got it to work now!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Produits

Version

R2022a

Question posée :

PT
le 5 Août 2022

Commenté :

PT
le 6 Août 2022

Community Treasure Hunt

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

Start Hunting!

Translated by