How to generate vector with non-linear spacing? (2024)

38 views (last 30 days)

Show older comments

Ryan about 15 hours ago

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing

Commented: Ryan about 14 hours ago

Accepted Answer: John D'Errico

Hello,

I am attempting to generate an array with non-linear spacing between the elements but struggling to figure out a way to impliment this. I need an array x of points spaced from a real, negative value a to a real, positive value b. Ideally the spacing should follow a Gaussian distribution such that many points are clustered about x=0 in the vicinity of some finite width d. Conversely the spacing should be large at the boundaries. More generally it doesn't have to be Gaussian but some guidance on a scheme where I can specify a length d<<|b-a| across which many points should be distributed would be really appreciated.

I tried to work out an algorithm of sorts from pen and paper but it didn't really work and resulted in something that did not appear to be immediately solveable.

Thanks

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

John D'Errico about 6 hours ago

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#answer_1498979

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#answer_1498979

Edited: John D'Errico about 6 hours ago

It sounds like you want a deterministic, non-random set of points. You can use the inverse gaiussian CDF to do what you want.

a = -2.5;

b = 3;

N = 40;

x = norminv(linspace(normcdf(a),normcdf(b),N));

xline(x,'r')

How to generate vector with non-linear spacing? (3)

So most dense at zero, and a density that drops off away from there. I chose limits that are not centered around zero, but had they been centered, the set would be perfectly symmetric.

Of course, you can adjust the speed of fall off, by use of a different variance on the implicit Gaussian.

1 Comment

Show -1 older commentsHide -1 older comments

Ryan about 6 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#comment_3237069

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#comment_3237069

Yes that's looking exactly like what I need, thanks so much!

Sign in to comment.

More Answers (2)

Matt J about 6 hours ago

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#answer_1498949

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#answer_1498949

Edited: Matt J about 6 hours ago

Open in MATLAB Online

a=-1;

b=+1;

d=1/(b-a)^2;

y=d*randn(1,500);

x=sort(y+(a+b)/2);

stem(x,x.^0); xlim([a,b])

How to generate vector with non-linear spacing? (6)

2 Comments

Show NoneHide None

Ryan about 6 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#comment_3237029

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#comment_3237029

Thanks for the suggestion, this is a possible option. Any way to get the spacing more regular?

Ryan about 6 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#comment_3237054

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#comment_3237054

Ah I see what I meant by Gaussian is not in the sense of a random distribution but of a spacing that followed a pattern akin to a contiunous Gaussian function. I had envisaged an algorithm that produces regular values

How to generate vector with non-linear spacing? (9)

Where Δis some constant. I don't think this algorithm "works" as such but I think it illustrates what I'm after. For what I am working on a random distribution may also work.

Sign in to comment.

Aquatris about 6 hours ago

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#answer_1498974

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2145269-how-to-generate-vector-with-non-linear-spacing#answer_1498974

Open in MATLAB Online

The answer from another question here:

A = 1;

B = 5;

std = .9; % need to play with this to get desired shape within desired range,

% if too high, it does not become a normal distribution

% if too low, it does not cover the whole A-B range

mean = 3;

step1Result = mean + std * randn(1e3,1); % create random data with mean and std

step2Result = min(max(step1Result,A),B); % make sure they end up in A-B range

hist(step2Result)

ylabel('# of occurence')

xlabel('Data Value')

How to generate vector with non-linear spacing? (11)

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Tags

  • array
  • vector

Products

  • MATLAB

Release

R2022a

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How to generate vector with non-linear spacing? (12)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

How to generate vector with non-linear spacing? (2024)
Top Articles
Palace Pizza Joplin
Nimbleaf Evolution
Riverrun Rv Park Middletown Photos
Culver's Flavor Of The Day Wilson Nc
Craigslist Free Stuff Appleton Wisconsin
Plus Portals Stscg
Green Bay Press Gazette Obituary
Mail Healthcare Uiowa
Clafi Arab
Hover Racer Drive Watchdocumentaries
Slmd Skincare Appointment
Superhot Unblocked Games
Dumb Money
Epro Warrant Search
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
Marvon McCray Update: Did He Pass Away Or Is He Still Alive?
Mission Impossible 7 Showtimes Near Marcus Parkwood Cinema
Village
When Does Subway Open And Close
Plost Dental
1145 Barnett Drive
Nottingham Forest News Now
Farm Equipment Innovations
Trust/Family Bank Contingency Plan
Emiri's Adventures
Roadtoutopiasweepstakes.con
Fbsm Greenville Sc
Mbi Auto Discount Code
Wcostream Attack On Titan
Rise Meadville Reviews
Mistress Elizabeth Nyc
Robeson County Mugshots 2022
Game8 Silver Wolf
Admissions - New York Conservatory for Dramatic Arts
Alpha Asher Chapter 130
Überblick zum Barotrauma - Überblick zum Barotrauma - MSD Manual Profi-Ausgabe
Davis Fire Friday live updates: Community meeting set for 7 p.m. with Lombardo
Mytime Maple Grove Hospital
Executive Lounge - Alle Informationen zu der Lounge | reisetopia Basics
Lucyave Boutique Reviews
Wilson Tire And Auto Service Gambrills Photos
Noh Buddy
Haunted Mansion Showtimes Near Millstone 14
Walmart Listings Near Me
Erica Mena Net Worth Forbes
Marine Forecast Sandy Hook To Manasquan Inlet
Treatise On Jewelcrafting
Tìm x , y , z :a, \(\frac{x+z+1}{x}=\frac{z+x+2}{y}=\frac{x+y-3}{z}=\)\(\frac{1}{x+y+z}\)b, 10x = 6y và \(2x^2\)\(-\) \(...
The 5 Types of Intimacy Every Healthy Relationship Needs | All Points North
300 Fort Monroe Industrial Parkway Monroeville Oh
Kobe Express Bayside Lakes Photos
Att Corporate Store Location
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated:

Views: 5527

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.