How to plot graphs successively using loop

2 visualizaciones (últimos 30 días)
okoth ochola
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;
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

Respuesta aceptada

Luca Ferro
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)

Más respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by