Code covered by the BSD License  

Highlights from
NDLINSPACE (v1.1, feb 2008)

4.0

4.0 | 1 rating Rate this file 13 Downloads (last 30 days) File Size: 2.5 KB File ID: #22875

NDLINSPACE (v1.1, feb 2008)

by Jos (10584)

 

03 Feb 2009 (Updated 03 Feb 2009)

Generalized LINSPACE: linearly spaced values between mutliple points

| Watch this File

File Information
Description

  NDLINSPACE - Generalized linearly spaced matrix for multiple points
 
    R = NDLINSPACE(M1,M2, N) returns a matrix of size [size(M1) N] holding
    N equally spaced points between corresponding point of M1 and M2. If N
    is smaller than 2, M2 is returned. R = NDLINSPACE(M1,M2) uses N = 100.
 
    For scalar inputs, NDLINSPACE(S1,S2,N) mimicks LINSPACE, returning
    equally spaced points between the S1 and S2. Example:
 
       ndlinspace(0, 2, 4)
         % -> 0 0.67 1.33 2.00
 
    For two M-by-1 column vectors, NDLINSPACE(V1,V2,N) returns a M-by-N
    matrix in which the k-th row holds the N equally spaced numbers between
    V1(k) and V2(k). Similary, for two 1-by-M row vectors, a N-by-M matrix
    is returned. Example:
 
       ndlinspace([0 ; 12 ; 10], [3 ;18 ; 11],4)
         % -> 0 1.00 2.00 3.00
         % 12.00 14.00 16.00 18.00
         % 10.00 10.33 10.67 11.00
 
    For two ND arrays of size P-by-Q-by-R-by-.. matrices, NDLINSPACE
    (M1,M2,N) returns a P-by-Q-by-R-by-..-by-N matrix, holding N equally
    space points between M1(i,j,k,..) and M2(i,j,k,..). Example:
 
       M1 = reshape(1:2*3*4*5,[2 3 4 5]) ;
       M2 = 10 * M1 ;
       size(M1) ; % ans = 2 3 4 5
       R = ndlinspace(M1,M2,5) ;
       squeeze(R(2,1,4,3,:)).'
          % ans = 68 221 374 527 680
       % Compare with LINSPACE for scalars
       linspace(M1(2,1,4,3),M2(2,1,4,3),5)
          % ans = 68 221 374 527 680
 
   In general, M1 and M2 have to have the same size. Scalar expansion is
   applied when one of the inputs is a scalar. Example:
       ndlinspace(0,[4 ; 8 ; -12],5) % expand M1
         % ans = 0 1 2 3 4
         % 0 2 4 6 8
         % 0 -3 -6 -9 -12
 
   See also linspace, logspace, repmat, interp1, squeeze

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Linearly spaced multidimensional matrix without loop

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
03 Feb 2009 Steeve AMBROISE

I tried to compare this function to linspaceNDim with this code:

clear
a=rand(20,30,5,10,19,4);
b = rand(size(a));
N = 5;

tic, c1 = linspaceNDim(a, b, N);toc
clear c1

tic, c2 = ndlinspace(a, b, N);toc

I find that linspaceNDim is 20 times faster then ndlinspace.

Steeve.

Please login to add a comment or rating.
Updates
03 Feb 2009

fixed minor typos

Tag Activity for this File
Tag Applied By Date/Time
matrices Jos (10584) 03 Feb 2009 16:38:36
values Jos (10584) 03 Feb 2009 16:38:36
interpolate Jos (10584) 03 Feb 2009 16:38:36
linear Jos (10584) 03 Feb 2009 16:38:36
space Jos (10584) 03 Feb 2009 16:38:36
matrix Jos (10584) 03 Feb 2009 16:38:36
matrix manipulation Jos (10584) 03 Feb 2009 16:38:36

Contact us at files@mathworks.com