Nested For Loop for 2D Matrix

조회 수: 3 (최근 30일)
BBB
BBB 2019년 11월 11일
댓글: Matt J 2019년 11월 11일
I want to create a nested for loop that essentially goes through a 2D matrix of 600x1000 dimensions, such that in every loop in both of the dimensions it picks out exactly 51x51 part of the 2D matrix in either of the dimensions and multiplies it to another 51x51 separate matrix.

채택된 답변

Matt J
Matt J 2019년 11월 11일
편집: Matt J 2019년 11월 11일
So then you want to extract random 51x51 submatrices? If so, then,
I=sort(randperm(600,51));
J=sort(randperm(1000,51));
submatrix= matrix(I,J);
  댓글 수: 2
BBB
BBB 2019년 11월 11일
Sorry if the question was not very clear. I have a data set which is 2D 600x1000 in dimensions. I have to create a nested for loop of the following format,
for ii = 1:1000
for jj = 1:600
end
end
....
which will go through the 1000 dim first taking the first 51x51 elements (the first column should be col 1-51 in the first loop, the second iteration sould be 2-52, third 3-53--as long as it reaches till the end). For the 600 dim as well, taking the first 51x51 elements (the first row should be 1-51 in the first loop, the second iteration sould be 2-52, third 3-53--as long as it reaches till the end). Each of these set of 51x51 should simultaneously be multiplied with a static set matrix that I have which is also 51x51.
Matt J
Matt J 2019년 11월 11일
Is it element-wise multiplication, or another kind? And what is to be done with each of the 51x51 multiplication results? In double floating point, this will require 10 GB of storage if they are kept simultaneously in memory,
>> (600-51)*(1000-51)*51^2*8/2^30
ans =
10.0965

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

추가 답변 (1개)

Matt J
Matt J 2019년 11월 11일
I vaguely wonder whether you are just re-inventing convolution
result = conv2(Matrix,staticMatrix,'valid');

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by