Plotting xlsx file data using a for loop

1 次查看(过去 30 天)
I need to plot a raw data in a xlsx file using the fit command. I need to use a for loop in order to plot the data in the file. I have written code for it but it does not work. The data file is linked as well, as I cannot describe it properly.
Allpops=xlsread('pops.xlsx');
T=[1960,2020];
%I need a for loop to create exp1 fits for all of them and plot these fits
%on the same graph.
for k=1:length(Allpops(1,:));
ft=fittype('exp1');
[Fit,gof]=fit(T,k,ft);
plot(T,Fit);
hold on;
drawnow;
end

采纳的回答

KSSV
KSSV 2021-6-28
Allpops=xlsread('pops.xlsx');
T = (1961:2020)' ;
%I need a for loop to create exp1 fits for all of them and plot these fits
%on the same graph.
for k=1:length(Allpops(1,:))
y = Allpops(k,:)' ;
Fit=fit(T,y,'poly2');
plot(Fit,T,y);
drawnow;
end
  1 个评论
Petch Anuwutthinawin
The code works but it makes a new graph every time the loop runs, it does not save all the data into just one graph. How do I make it save all the data onto just one graph?
Also how do I make it stop plotting the raw data, I dont see a line of code that should plot raw data.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by