help-octave
[Top][All Lists]
Advanced

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

Re: building dynamic ranges from matrix


From: avlas
Subject: Re: building dynamic ranges from matrix
Date: Tue, 21 Nov 2017 16:27:21 -0500

El dimarts, 21 de novembre de 2017, a les 14:26:29 EST, avlas va escriure:

  El dimarts, 21 de novembre de 2017, a les 14:06:38 EST, Anthony Gumbs va 
escriure:
  
    Example had an error it in. Should read
    
    range_start_end = [1,5 ; 4 7];
    should produce a vector containing [1:5,*4:7*],  The final result being
    [1,2,3,4,5,4,5,6,7].
    
    On Nov 21, 2017 12:47 PM, "AG" <address@hidden> wrote:
    
    
    Here is my problem.
    
    Given a N X 2 matric, build a single vector that contains the range of
    numbers between (:,1) and (:,2).
    For example:
    
    range_start_end = [1,5 ; 4 7];
    should produce a vector containing [1:5,2:4],  The final result being
    [1,2,3,4,5,4,5,6,7].  I am trying to do this with just simple matrix
    operation if possible- no if's then's array functions etc.
    
    I have tried this a few ways but can't seem to get it to work.. so I'd love
    to hear any ideas.
    -Much appreciated!
    
    
    
    --
    Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
    
    _______________________________________________
    Help-octave mailing list
    address@hidden
    https://lists.gnu.org/mailman/listinfo/help-octave
    
  You can try the following, it worked for me:
  
  x = [1 5;4 7];
  y = arrayfun(@(x,y) x:y, x(:,1), x(:,2), "UniformOutput", false);
  z = [y{:}];
  
  This code generalizes to any number of rows.
  
  a.

The above message didn't seem to reach the mailing list :/
Trying again...

a.



reply via email to

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