Effacer les filtres
Effacer les filtres

How to plot graphs successively using loop

2 vues (au cours des 30 derniers jours)
okoth ochola
okoth ochola le 10 Fév 2023
Commenté : Luca Ferro le 14 Fév 2023
Hi, I would want to plot data successively using for loop. I tried the code below, but the code only plots the first graph and stops. How can I plot the graph successsilvely. You can use any data for illustration. The code should selcet montlhy data from a data set, find the parameters and then use the results to generate 12 graphs. The code does all these successfully except darwing the graphs, it draws only the first one. How can I modify my code to be able to darw the graphs?
A=input('Enter wind speed\n')
B=input('Ener matrix of month\n')
% monthly Weibull parameters
c=12;
a1=400;
C1=[A B];
for k=1:1:c
selectedRowsLogicalIndices = B == k;
if numel(B(B==k))>a1;
subsetAdata = A(selectedRowsLogicalIndices);
Monthly_parameters(:,k)= wblfit(subsetAdata);
[Overal_parameters]= wblfit(A);
if k==c
display(Monthly_parameters)
display(Overal_parameters)
figure()
histogram(A,50,'Normalization','probability')
hold on
plot(A,wblpdf(A,Overal_parameters(1),Overal_parameters(2)))
legend('Observed Samples','Estimated Distribution')
xlabel('Annual probabilty density')
ylabel('wind speed m/s')
hold off
%mothly plots
%january
figure()
histogram(subsetAdata,50,'Normalization','probability')
hold on
plot(subsetAdata,wblpdf(subsetAdata,Monthly_parameters(1,k),Monthly_parameters(2,k)))
legend('Observed Samples','Estimated Distribution')
xlabel('monthly probabilty density')
ylabel('wind speed m/s')
hold off
end
else
F(k,:)=find(C1(:,2) ==k);
if k==c
display(F)
end
end
end

Réponse acceptée

Luca Ferro
Luca Ferro le 10 Fév 2023
Modifié(e) : Luca Ferro le 10 Fév 2023
I think the issue is with the if statement:
if k==c
since the plotting happens inside of the if statement it will only happen when the condition is true, in this case only on the 12th run. So what you get is only 1 graph, of the 12th run in the loop (when c==k==12)
  1 commentaire
Luca Ferro
Luca Ferro le 14 Fév 2023
did this solve your issue?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Discrete Data Plots dans Help Center et File Exchange

Tags

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by