How to plot graphs successively using loop
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!