Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: Subscripted dimension mismatch
Posted:
Jan 14, 2013 10:23 AM
|
|
"Jacob Moses" <jacobfmoses@gmail.com> wrote in message news:kcs0nh$aav$1@newscl01ah.mathworks.com... > 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);
Unless test is a row vector, this won't work. The expression on the left of the equals sign represents a scalar (a 1-by-1 chunk of split{1}) while the expression on the right of the equals sign represents a size(test, 1)-by-1 chunk of data. The latter is too big to fit into the former unless as I said size(test, 1) is 1.
> elseif n>12021 > split{2}(n-12021)=test(:,n)
Ditto.
> end > end > Subscripted assignment dimension mismatch. > > If anyone can tell me what is going on, I would greatly appreciate it. > Thanks in advance.
There's no need for a loop here. Either:
1) If test is of odd length, pad it with a NaN then RESHAPE it. Otherwise just RESHAPE it. 2) split{1} = test(:, 1:12021); split{2} = test(:, 12022:end);
If test may vary in size, you could use floor(end/2) in the second expression to generalize it.
-- Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com
|
|
|
|