필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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

채택된 답변

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by