Clear Filters
Clear Filters

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

2 views (last 30 days)
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

Accepted Answer

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

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!