Be the first to rate this file! 5 Downloads (last 30 days) File Size: 15.77 KB File ID: #26503
image thumbnail

space125: Almost equally spaced points in logarithmic space

by Petr Pošík

 

28 Jan 2010

Generate points ..., 1, 2, 5, 10, 20, ... often useful for log-plots when integer values needed.

| Watch this File

File Information
Description

Suppose we need to generate points equally spaced in logarithmic space. This is often useful with semilogx, semilogy, or loglog plots and can be easily accomplished by the logspace command. Let's generate 10 values between 1 and 1000 equally spaced in the log-space:

>> Dlogspace = logspace(log10(1),log10(1000),10)
Dlogspace =
  1.0e+003 *
  0.0010 0.0022 0.0046 0.0100 0.0215 0.0464 0.1000 0.2154 0.4642 1.0000
    
That's great. But sometimes, the D variable must be integer. Well, OK, let's round the values.

>> Drounded = round(Dlogspace)
Drounded =
  1 2 5 10 22 46 100 215 464 1000
           
Again, this is easy. But the values are not easy to remember, since they are different in each decade.

And this is the moment where space125 comes in. It generates values of 1, 2, and 5 multiplied by powers of 10:

>> D = space125(1,1000)
D =
  1 2 5 10 20 50 100 200 500 1000

Other examples:
>> D = space125(1,789)
>> D = space125(0.0235, 5.7)

Pros and cons of space125:

The function |space125| generates 3 easy-to-remember integer points in each decade of the scale. You cannot change it (that's the minus), but very often you needn't change it (that's the plus). The values 1, 2, and 5 are based on my personal experience and are sufficient for the majority of my needs.

If the domain should be covered with higher density, I suggest using the
>> round( logspace(log10(xmin),log10(xmax),nPoints) )
command.

Of course, if there is no need for integer values, use the original MATLAB logspace command.

MATLAB release MATLAB 7 (R14)
Other requirements Uses bsxfun
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
semilogx Petr Pošík 28 Jan 2010 11:52:54
semilogy Petr Pošík 28 Jan 2010 11:52:54
loglog Petr Pošík 28 Jan 2010 11:52:54
logspace Petr Pošík 28 Jan 2010 11:52:54
integer Petr Pošík 28 Jan 2010 11:52:54
ploting Petr Pošík 28 Jan 2010 11:52:54
design of experiments Petr Pošík 28 Jan 2010 11:52:54
doe Petr Pošík 28 Jan 2010 11:52:54
logarithmic scale Petr Pošík 28 Jan 2010 11:52:54

Contact us at files@mathworks.com