필터 지우기
필터 지우기

How to save multiple matrices in each iteration of a for loop into a structure?

조회 수: 2 (최근 30일)
A = imread('Ish.JPG');
A = im2single(squeeze(mean(A,3)));
A = im2double(A);
[pyrRef,pind] = buildLpyr(A,'auto');
nLevels = 7;
kernelx = [0.0, 0.0, 0.0; 0.5, 0.0, -0.5; 0.0, 0.0, 0.0];
kernely = [0.0, 0.5, 0.0; 0.0, 0.0, 0.0; 0.0, -0.5, 0.0];
for k = 1:nLevels
subband = pyrBand(pyrRef, pind, k);
rx(k) = conv2(subband(k),kernelx);
ry(k) = conv2(subband(k),kernely);
end
Here, for each 'k' (k = 1:7) there will be 3 matrices (subband, rx, ry). So, I want to save this in a structure of diemnsion (7 X 3). How do I do that within this loop?

채택된 답변

Matt J
Matt J 2022년 11월 29일
clear S
for k = nLevels:-1:1
S(k).subband = pyrBand(pyrRef, pind, k);
S(k).rx = conv2(subband(k),kernelx);
S(k).ry = conv2(subband(k),kernely);
end
  댓글 수: 2
Anisia Anil
Anisia Anil 2022년 11월 30일
편집: Anisia Anil 2022년 11월 30일
Value = S(k).subband.*S(k-1).subband + S(k).rx.*S(k-1).rx + S(k).ry.*S(k-1).ry;
If I have to compute this value for each iteration, how do I do that? (Values at S(k-1) are previously defined.) The matrices "subband", "rx", and "ry" have different dimensions. So it is showing "Arrays have incompatible sizes for this operation" when try to implement this equation. Also, the matrix dimensions will be different for each iterations. So, I need to generalize this matrix addition with different dimensions. How do I do that? Can you please help?

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

추가 답변 (0개)

카테고리

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