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

7 views (last 30 days)
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?

Accepted Answer

Matt J
Matt J on 29 Nov 2022
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 Comments
Anisia Anil
Anisia Anil on 30 Nov 2022
Edited: Anisia Anil on 30 Nov 2022
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?

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!