Plotting xlsx file data using a for loop

1 view (last 30 days)
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

Accepted Answer

KSSV
KSSV on 28 Jun 2021
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 Comment
Petch Anuwutthinawin
Petch Anuwutthinawin on 28 Jun 2021
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!