How to quickly create figures from a matrix with different specimen

2 visualizzazioni (ultimi 30 giorni)
I have some data that I am importing into MATLab. I have broken it down to the specimen number and the load it was experiencing. For example
ans =
1.0000 21.5564
1.0000 18.1025
1.0000 17.8211
1.0000 17.4481
2.0000 25.0227
2.0000 22.3182
How could I write a for loop or an if loop that automatically creates a figure that adds each specimen to the figure once the specimen number increases?

Risposta accettata

Nick Annis
Nick Annis il 12 Lug 2017
I answered my own question. The code is below for anyone that is ever going to reference this. It also splits it into two figures depending on the specimen number. That way there isn't one overcrowded figure.
N=1; %Starts the for loop/ allows it to increase/match the specimen number
legendtext1=''; %creates a character so an array of each specimen number can be created for the legend
legendtext2='';
for A= N:9
[A]=find(bayonetdata==N); %Creates matrix that will match the specimen number only
if N>=5
hold on
figure(2)
plot(1:length(A),bayonetdata([A(1):A(end)]',2))
grid on
legendtext2= [legendtext2; num2str(N)]; % creates the matrix for the plot legend numbering
end
if N<5
hold on
figure(1)
plot(1:length(A),bayonetdata([A(1):A(end)]',2)) %plots the specimen number only test forces
legendtext1= [legendtext1; num2str(N)]; % creates the matrix for the plot legend numbering
grid on
end
hold off
N= N+1 ;
end
finallegend1=strcat(string('Bayonet '),legendtext1); %converts the legend to a string so that it can be manipulated easier within the legend and look cleaner
finallegend2=strcat(string('Bayonet '),legendtext2); %converts the legend to a string so that it can be manipulated easier within the legend and look cleaner
figure(1)
xlabel('Test Run')
ylabel('Ejection Force (kgf)')
grid on
title('Bayonet degredation over repeated housing ejections')
legend(finallegend1)
figure(2)
xlabel('Test Run')
ylabel('Ejecetion Force (kgf)')
grid on
title('Bayonet degredation over repeated housing ejections')
legend(finallegend2)

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by