Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Subscripted assignment dimension mismatch.

Asked by Jacob Moses on 12 Jan 2013

Hello, I am attempting to separate a large matrix into two parts for kernel formation for clustering with a kernel k-means algorithm. While I would ordinarily jus reshape it into a third dimension, this option is impossible given that the number of columns in the matrix in question is odd (24021). I have been unable to perform any of the things that I have seen before, such as indexing. Below is the method I tried, which returned the above error message.

EDU>> for n=1:24041
if n<=12021
split{1}(n)=test(:,n);
elseif n>12021
split{2}(n-12021)=test(:,n)
end
end
Subscripted assignment dimension mismatch.

If anyone can tell me what is going on, I would greatly appreciate it. Thanks in advance.

0 Comments

Jacob Moses

Products

2 Answers

Answer by Walter Roberson on 12 Jan 2013
Accepted answer
split{1} = test(:,1:12021);
split{2} = test(:,12022:end);

1 Comment

Jacob Moses on 12 Jan 2013

This worked perfectly, and was easiest for me to understand. Thank you so much!

Walter Roberson
Answer by José-Luis on 12 Jan 2013
Edited by José-Luis on 12 Jan 2013

You are probably trying to assign a matrix to a scalar:

 split{1}(n)=test(:,n);

split{1}(n) is most likely a scalar

test(:,n) is probably a column vector

3 Comments

Walter Roberson on 12 Jan 2013

test(:,1) would have to be a row vector.

José-Luis on 12 Jan 2013

No, it is a column vector as far as I understand it.

José-Luis on 12 Jan 2013

Now I see what you meant. I need some coffee.

José-Luis

Contact us