How to operate on a specified parts of a matrix in a loop?

조회 수: 1 (최근 30일)
Matlabio
Matlabio 2017년 3월 13일
댓글: Matlabio 2017년 3월 13일
Hi everyone,
I needed help with my script, all suggestions would be very helpful. Suppose that I have a 100x50 matrix. I need to partition it into 10 submatrices or blocks, and operate on the first submatrix (say 10 first rows) in a for loop, record the results; then move on to the next 10 rows, etc. In essence, these submatrices are my different resampled data sets that I need to treat as separate and operate upon in my for loop, and record the results for each sample. How can I index and refer to these samples? Thanks in advance for all help.

채택된 답변

Alexandra Harkai
Alexandra Harkai 2017년 3월 13일
It would depend on the particular 'operation'. If your 'operation' works on a 10*50 matrix, and for example produces a scalar value, then you could record this for all 10 data sets:
size_of_dataset = 10;
n_datasets = size(myMatrix, 1) / size_of_dataset; % check how many observations are there
res = zeros(1, n_datasets); % initialise results as zeros
for k = 1:n_datasets
res(k) = myOperation( myMatrix(k-1+(1:size_of_dataset),:) ); % get all data for the dataset
end
It would be easier to keep track of the separate datasets if it were stored in a 10*10*50 array instead, then you could loop through a 'layer' each time.
  댓글 수: 1
Matlabio
Matlabio 2017년 3월 13일
The operation in my script is actually a huge loop that produces once again, say a 10x50 array. I was just trying to conceptualize how this would work in this case and apply it to my huge bootstrapped dataset. I'm going to try your suggestion shortly, thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by