How to specify a variable (using linspace) like this?
7 次查看(过去 30 天)
显示 更早的评论
Distance between first and second point and the distance between second last and last point is 0.5h. All other distances between the neighboring points is h. How to create a grid of say N points that do not include the first and the last point in the grid?
0 个评论
回答(2 个)
Andrei Bobrov
2012-10-8
编辑:Andrei Bobrov
2012-10-8
afirst = 2;
h = .5;
N = 5;
out = afirst + cumsum([0, .5*h,ones(1,N-1)*h,.5*h])
or
out = [afirst,linspace(afirst + .5*h,afirst + .5*h + (N-1)*h,N),afirst + N*h];
or
a = [2 6];
N = 5;
L = linspace(a(1),a(2),N+1)
L(2:end) = L(2:end)-diff(a)/N*.5
out = [L,a(end)];
2 个评论
Taha
2012-10-8
He has asked "do not include the first and the last point". I think your solutions include the first and last points.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!