Linspace using matrix input matlab

后端 未结 1 771
一生所求
一生所求 2020-12-12 02:12

My question seems wierd, because I know that we can\'t use a matrix as input in linspace(x1,x2,n) function. But my question is more something like : I have a ve

相关标签:
1条回答
  • 2020-12-12 02:53

    Maybe something using interp1, to interpolate something like:

    [0    0    0    ... 0 ]
    [A(1) A(2) A(3) ... A(N)]
    

    with N rows .... For instance:

    N = 5;
    Amax = 15;
    A = linspace(0, Amax, N);
    
    x = [0 1];
    y = zeros(2, N);
    y(2, :) = A;
    
    B = interp1(x, y, linspace(0, 1, N))
    

    Which will give:

    B =
    
         0         0         0         0         0
         0    0.9375    1.8750    2.8125    3.7500
         0    1.8750    3.7500    5.6250    7.5000
         0    2.8125    5.6250    8.4375   11.2500
         0    3.7500    7.5000   11.2500   15.0000
    

    Not sure it will be any faster than a for loop or that even get the point here :)

    0 讨论(0)
提交回复
热议问题