Plotting xlsx file data using a for loop

1 回表示 (過去 30 日間)
Petch Anuwutthinawin
Petch Anuwutthinawin 2021 年 6 月 27 日
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
Petch Anuwutthinawin 2021 年 6 月 28 日
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 Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by