Azzera filtri
Azzera filtri

Writing a 3x3 matrix as the 3rd and 4th dimesions of a multidimenstioanl array

2 visualizzazioni (ultimi 30 giorni)
I have a function that returns a 3x3 covariance matrix (and a 1x3 mean value vector). I would like to "insert" this as the 3rd and 4th dimensions of a (l , w , 3, 3) array (and a (l, w, 3) array). I can do this with a couple of for loops. I would think that Matlab has a more elegant/efficient way of doing this. Thanks.
Below covRGBa is a 3x3 matrix and aveRGBa is a 1x3 vector
[covRGBa,aveRGBa] = covary(RGB,r,c,xleft,xright,ytop,ybottom,n,perimeter);
for i = 1:3
aveRGB(c,r,i)=aveRGBa(i);
for j = 1:3
covRGB(c,r,i,j)=covRGBa(i,j);
end
end

Risposta accettata

Rik
Rik il 14 Mag 2020
This should work:
[covRGBa,aveRGBa] = covary(RGB,r,c,xleft,xright,ytop,ybottom,n,perimeter);
aveRGB(c,r,:)=aveRGBa;
covRGB(c,r,:,:)=covRGBa;

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by