Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: sparse matrix operation in V5.x
Replies: 2   Last Post: May 4, 1998 2:18 AM

 Messages: [ Previous | Next ]
 H.J. Wang Posts: 12 Registered: 12/7/04
Re: sparse matrix operation in V5.x
Posted: Apr 30, 1998 1:19 PM

> 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:penny@mathworks.com
> 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!

H.J. Wang

Date Subject Author
4/30/98 H.J. Wang
4/30/98 H.J. Wang
5/4/98 Axel Hecht