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!