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

1 次查看(过去 30 天)
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