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

6 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Matt J
Matt J am 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 Kommentare
Anisia Anil
Anisia Anil am 30 Nov. 2022
Bearbeitet: Anisia Anil am 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by