Plotting xlsx file data using a for loop

조회 수: 1 (최근 30일)
Petch Anuwutthinawin
Petch Anuwutthinawin 2021년 6월 27일
댓글: Petch Anuwutthinawin 2021년 6월 28일
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 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