How to plot graphs successively using loop

조회 수: 2 (최근 30일)
okoth ochola
okoth ochola 2023년 2월 10일
댓글: Luca Ferro 2023년 2월 14일
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

채택된 답변

Luca Ferro
Luca Ferro 2023년 2월 10일
편집: Luca Ferro 2023년 2월 10일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by