Filter löschen
Filter löschen

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

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

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by