Uneven linspacing of an array

21 ビュー (過去 30 日間)
Ran Kagan
Ran Kagan 2021 年 1 月 26 日
回答済み: Daniel Pollard 2021 年 1 月 26 日
I want to create an array with unequal spacing. I have the parameter len (of a size [1x250]) with the following values inside:
0.050077530845678 , 0.055555988803619, ...... , 1.414213562373095.
There is a constant difference between neighboring values, of 0.005478457957941.
I need to have the linspaced array with values which are spaced very densly at the begining (as my gradient there is more substantial), while getting more and more sparsed til the end.
Thanks!

回答 (2 件)

Star Strider
Star Strider 2021 年 1 月 26 日
I am not certain of the result you want.
One option would be to use logspace instead of linspace, since that would produce logarithmically-spaced vector elements that would be denser at the beginning than at the end. Other transformations using linspace or logspace are also options, depending on what you want to do.

Daniel Pollard
Daniel Pollard 2021 年 1 月 26 日
If I understand right, you have a vector len, and you want to have a vector x such that diff(x)=len. In that case, you can use the cumulative sum function, cumsum:
x = cumsum(len) - len(1) + init_value;
where I have subtracted the first value in len so that the initial component of x is zero, then you can add whatever initial component you like.
Is that what you're after?

カテゴリ

Help Center および File ExchangeProgramming Utilities についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by