Hello, I have data that is n x m (rows,column). I want to read each column and perform some analysis on the data prior to moving on to another column and performing the same analysis.
Is there a method on how to perform this reiterative process? Thanks,

 채택된 답변

Voss
Voss 2022년 2월 1일

0 개 추천

If you have an n-by-m matrix you can do as follows:
n = 100;
m = 50;
data = randn(n,m);
results = cell(1,m);
for jj = 1:m
results{jj} = perform_analysis(data(:,jj));
end
Where perform_analysis() is a function that performs the analysis you want to do on each column and returns something.
If instead your data is in a file, it may or may not be convenient to read it by column, depending on the file format.

댓글 수: 4

hello @Benjamin. would you please light up about this error? is it matlab tool related error?
Unrecognized function or variable 'perform_analysis'.
Error in Untitled47 (line 9)
results{jj} = perform_analysis(data(:,jj));
Michael Angeles
Michael Angeles 2022년 2월 1일
Thank you, I forgot to state that the data are in cells array.
Voss
Voss 2022년 2월 1일
@Arif Hoq: perform_analysis() is meant to be a stand-in for whatever analysis needs to be done on each column of data.
@Michael Angeles: The indexing syntax is the same for a cell array. You'd be dealing with an n-by-1 cell array rather than an n-by-1 column vector each time through the for loop.
Michael Angeles
Michael Angeles 2022년 2월 1일
Thank you for your help, I was able to get the program running.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2022년 2월 1일

댓글:

2022년 2월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by