Home Linspace using matrix input matlab

# Linspace using matrix input matlab

John
1#
John Published in 2018-02-14 09:21:03Z
 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 vector A=linspace(0,Amax,N), and I want to build a serie of vector B_k or big matrix B_k=linspace(0,A(k),N) but without making a for loop that slows down my whole calculation. % already defined A rGC=linspace(0,75e-7,N); for k=1:N r=rGC(k); v=linspace(0,A*r,N); y=f(r,v); INT=trapz(v,y); % The same for 8 more integrals end 
CitizenInsane
2#
 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 :)