How to operate on a specified parts of a matrix in a loop?
1 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Alexandra Harkai
on 13 Mar 2017
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.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!