필터 지우기
필터 지우기

Assignment has more non-singleton rhs dimensions than non-singleton subscripts

조회 수: 1 (최근 30일)
Hi guys,
I am a Matlab newbie. I am trying to squeeze elements from a 3-dimensional matrix on to a 2-dimensional matrix. The size of my 3 dimensional matrix is 11 * 11 * 2871, and it is essentially a variance-covariance matrix with variace reported on the diagonal and covariance appearing on off-diagonals. I am running the following code but it results in the following error
"Assignment has more non-singleton rhs dimensions than non-singleton subscripts"
for i= 1:11
for j = 2:11
corr(i,j) = squeeze(HT(i,j,:))
end
end
Any help would be appreciated. Thanks!
  댓글 수: 3
Obaidur Rehman
Obaidur Rehman 2017년 9월 9일
편집: Obaidur Rehman 2017년 9월 9일
Thank you Jose for your swift response. I am sorry I don't quite follow what you mean, but following is a description of what I would like to achieve.
I have a 3 dimensional variance-covariance matrix for 11 different countries over a period of 2871 days (referred to as HT in the code below). The size of the matrix is 11*11*2871 with rows 1 through 11, columns 1 through 11 and pages 1 through 2871. What I wish to achieve is to extract the element corresponding to the first row and second column (i.e. covariance between country 1 and 2) for day 1 through 2871, and similarly for all other country pairs.
However, I would like to conduct this in a loop to save myself the time and hassle. The code I am using is the following
corr = zeros(2871,110);
for i= 1:11
for j = 2:11
corr(i,j) = squeeze(HT(i,j,:))
end
end
As I pointed earlier in the question that it generates an error message
"Assignment has more non-singleton rhs dimensions than non-singleton subscripts"
I am able to achieve the task by manually coding the country pairs. For example I use the following code to extract all daily covariances between country 1 and 2, and this works just fine, however its very time consuming to do this for each possible pair of countries.
corr12= squeeze(HT(1,2,:))
I hope this clarifies a little. Thanks once again!
José-Luis
José-Luis 2017년 9월 9일
I don't get why you need a loop. Why don't you just index the values you need.

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2017년 9월 9일
That error appears when you try to store a n dimension in a initialized data which is dimensioned different to n. You try replacing line:
corr(1,2,:) = squeeze(HT(1,2,:))
With exact dimensions of RHS or initialize LHS as a cell.
corr{1,2} = squeeze(HT(1,2,:))
  댓글 수: 1
Obaidur Rehman
Obaidur Rehman 2017년 9월 9일
편집: Obaidur Rehman 2017년 9월 9일
Hi KSVV,
Thanks for taking time to look into my query. My problem is not extracting the relevant covariance by explicitly specifying the row and column numbers, but trying to run it in a for loop, as I have indicated above.

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by