Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Matt J
Matt J il 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 Commenti
Anisia Anil
Anisia Anil il 30 Nov 2022
Modificato: Anisia Anil il 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?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by