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.
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!