Clear Filters
Clear Filters

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

1 view (last 30 days)
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 Comments
Obaidur Rehman
Obaidur Rehman on 9 Sep 2017
Edited: Obaidur Rehman on 9 Sep 2017
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!

Sign in to comment.

Answers (1)

KSSV
KSSV on 9 Sep 2017
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 Comment
Obaidur Rehman
Obaidur Rehman on 9 Sep 2017
Edited: Obaidur Rehman on 9 Sep 2017
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.

Sign in to comment.

Categories

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

Community Treasure Hunt

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

Start Hunting!