如何在Matlab中创建非线性间隔矢量? [英] How to create nonlinear spaced vector in Matlab?
问题描述
我正在尝试创建一个等高线图,其焦点位于1到1.05的特定有限范围内.同时,我需要非常接近1的高分辨率.我想我可以使用类似以下的方法,但是间距看起来仍然是线性的
I'm trying to create a contour plot with focus around a particular finite range from 1 to 1.05. At the same time, I need very high resolution closer to 1. I thought I could use something like the following but the spacing still looks linear
out=exp(linspace(log(1),log(1.05),100))
plot(diff(out))
当边界太紧时,增强间距非线性的最佳方法是什么?同样,我需要将高密度保持在1附近,并且分辨率会以非线性方式逐渐降低.我有一些想法,但我认为某人可能会快速使用2衬板或类似的东西.
What is the best way to enhance the nonlinearity of the spacing when the bounds are so tight? Again, I need to maintain high density near 1 with the resolution tapering off in a nonlinear way. I have a few ideas but I thought someone might have a quick 2 liner or something of the sort.
推荐答案
而不是应用函数 f(x)= e x ,以获得更陡峭"的非线性,而是应用 f(x)= e ax
instead of applying the function f(x) = ex, to get a 'steeper' non-linearity, rather apply f(x) = eax
n = 20;
a = 100;
lower = 1;
upper = 1.05;
temp = exp(linspace(log(1)*a,log(1.05)*a,n))
% re-scale to be between 0 and 1
temp_01 = temp/max(temp) - min(temp)/max(temp)
% re-scale to be between your limits (i.e. 1 and 1.05)
out = temp_01*(upper-lower) + lower
现在plot(diff(out),diff(out),'o')
产生
请注意,您可以对logspace
使用与上面完全相同的缩放方案,因此只需使用
Note that you can use the exact same scaling scheme above with logspace
so just use
temp = logspace(...)
然后其余的都一样
这篇关于如何在Matlab中创建非线性间隔矢量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!