> Hello H.J. Wang, > > I tried the following in versions 5.0 and 5.2 on the PC: > > x = rand(12,4); > y = rand(10,4); > x(1:3,:) = y(4:6,:); > > Both worked successfully. > > x and y had different numbers of rows, but the lengths of the index > vectors (in this case 3) were the same in both cases. > > Am I not understanding what you are doing correctly? > > -- Penny. > ==================================================== > Penny Anderson mailto:firstname.lastname@example.org > The MathWorks, Inc. http://www.mathworks.com > 24 Prime Park Way Phone: (508) 647-7506 > Natick MA 01760 Fax: (508) 647-7002
Thanks for Penny's prompt reply. Now I know where the problem really is. It's not in whether the maxtrix is sparse, as I have previously suspected, but in whether you have sort of "declare" a new matrix in advance. For example, the following codes work in version 4.x but not 5.x:
x = sparse(rand(20,4)); y(1:4,:) = x(2:5,:);
In version 5.x, you have to do something like:
x = sparse(rand(20,4)); y = zeros(10,4); y(1:4, :) = x(2:5,:);
That is, you have to "declare" the matrix y before assigning values. Compare to my original concern, this seems to be a minor problem and can be easily fixed. However, I miss version 4.x's functionality in this regard!