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

6 ビュー (過去 30 日間)
Anisia Anil
Anisia Anil 2022 年 11 月 29 日
編集済み: Anisia Anil 2022 年 11 月 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 月 29 日
Thank you.
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by