# How to plot graphs successively using loop

3 visualizaciones (últimos 30 días)
okoth ochola el 10 de Feb. de 2023
Comentada: Luca Ferro el 14 de Feb. de 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;
[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()
hold on
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
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Luca Ferro el 10 de Feb. de 2023
Editada: Luca Ferro el 10 de Feb. de 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 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Luca Ferro el 14 de Feb. de 2023

Iniciar sesión para comentar.

### Categorías

Más información sobre Line Plots en Help Center y File Exchange.

R2016a

### Community Treasure Hunt

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

Start Hunting!

Translated by