help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: matrix-vector-op class ?


From: Paul Kienzle
Subject: Re: matrix-vector-op class ?
Date: Fri, 7 Apr 2000 15:45:04 +0100 (BST)

Jonathan King wrote:
[snip]
>So that gives us, for c a column vector, r a row vector and M an
>appropriate matrix:
>
>   c .* M  => row scaling
>   r .* M  => column scaling
>   M .* c  => column scaling
>   M .* r  => hmm...
>
>I guess some people might want row scaling in the last case, but what I
>think might be more useful is returning a matrix with cols(r) times as
>many columns as M, where each submatrix the size of the original M is 
>r(n)*M for 0<n<cols(r).  In otherwords, repmat with scalar multiplication.

And what if you want to repeat the rows?  That would be M .* c, no?
So v .* M does scale only but M .* v does repeat and scale.  Sounds 
confusing to me.  

How about a repmat() function for your case?  Something like:
    function A = repmat(M,v)
        [rv cv] = size(v); 
        [rM cM] = size(M);
        if (rv>1)
           A = M(:,rem([0:rv*cM-1],cM)-1);  ## build repeated matrix
           scale=v(:,ones(1,cM))';          ## build scaling vector
           A = A .* scale(:)';              ## using new scale operator
        else
           A = M(rem([0:cv*rM-1],rM)-1,:);
           scale=v(ones(1,rM),:);
           A = scale(:) .* A;
        endif
Actually, you can do this now by changing scale(:) to diag(scale(:)) and 
".*" to "*":
    function A = repmat(M,v)
        [rv cv] = size(v); 
        [rM cM] = size(M);
        if (rv>1)
           A = M(:,rem([0:rv*cM-1],cM)-1);  ## build repeated matrix
           scale=v(:,ones(1,cM))';          ## build scaling vector
           A = A * diag(scale(:));          ## using new scale operator
        else
           A = M(rem([0:cv*rM-1],rM)-1,:);
           scale=v(ones(1,rM),:);
           A = diag(scale(:)) * A;
        endif
This doesn't extend to addition and subtraction though.

Paul Kienzle
address@hidden



-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]