필터 지우기
필터 지우기

Read row of data from excel file and step/iterate through each row when program is looped

조회 수: 21 (최근 30일)
Good day,
Trying to read 1 row of data each time program loops from excel file. Excel contains 2 columns of data. Each time my program loops, therefore updating values of Data1 and Data2.
Below extract of code reading imported excel file;
Disp('Currently importing from excel raw data file')
Data = xlsread('Data');%reading excel file
newData1 = Data(:,1);Reading column 1
newData2 = Data(:,2);%Reading column 2
Objective is to update equations as new data is measured, measuring using A1 and B1 1st loop, for instance.
measuring A2, B2, - 2nd iteration of programm/loop, etc....
Above is finite set of excel data, for simulation.
Thanks in advance,
kind regards Vincent
  댓글 수: 6
Guillaume
Guillaume 2020년 1월 10일
So, if the file is fixed why does it need to be read in a loop?
Sorry, I'm a bit confused as to what you have as input and what you want as output.
Vincent Hodnett
Vincent Hodnett 2020년 1월 11일
편집: Vincent Hodnett 2020년 1월 11일
Hello Guillaume,
Apologies, let try to clarify question; what mean or in other words;
  • Step.2 Initially the program reads Row1 of data to be used in(Row1 = Xk_p matrix) Step.2 Predicted State Matrix calculation: Xk_p used to calculate Xkp
  • Step.3 is only used in 1st iteration of program, Ans = Pk_p
  • Step.4 uses the Pk_p calculated in Step.3 to get Pk
  • Step.5 gain is calculated using both Pk and Pk_p
  • Step.6 New measurement is read Row2
  • Step.7 Uses Newmeasurement of Row2 from Step.6 and also the previous Xkp value which have calculated from Step.2 are used to calculate Current State Matrix Xk_p
  • Step.8 Uses result of Step.4 (Pkp) Predicited Process Covariance and Gain K from step.5 to calculate: New updated Process Covariance Pk_p
  • Step.9 uses the values calculated in step.8 and 9 to update Step.2 and Step.4 equations. i.ie new Xk_p is used in step.2 equation, new Pk_p is used step.4 equation to recalulate both Xkp and Pk.
(Step.3 is skipped after initial iteration)
This is what intending to to do, but issue implementing it above(variable naming/updating and repeating program), hope have clarified question.
Thanks,
kind regards Vincent

댓글을 달려면 로그인하십시오.

채택된 답변

Meg Noah
Meg Noah 2020년 1월 8일
Probably not the best way, but it works:
irow = 1;
Data = xlsread('fakedata.xlsx','Sheet1',['A' num2str(irow) ':B' num2str(irow)]);
while (~isempty(Data))
fprintf(1,'%f %f\n',Data(1),Data(2));
irow = irow + 1;
Data = xlsread('fakedata.xlsx','Sheet1',['A' num2str(irow) ':B' num2str(irow)]);
end
  댓글 수: 1
Guillaume
Guillaume 2020년 1월 10일
Comment by Vincent Hodnett mistakenly posted as an answer:
Hello Meg, Thanks for the advice, shall give it a go and let you know.
kind regards Vincent

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by