- #1

- 590

- 0

Code:

`A=-10+20*rand(5)`

if A(i,j)>10, A(i,j)=10 and the same for -10, but there must be a better way.

- Thread starter Dell
- Start date

- #1

- 590

- 0

Code:

`A=-10+20*rand(5)`

if A(i,j)>10, A(i,j)=10 and the same for -10, but there must be a better way.

- #2

MATLABdude

Science Advisor

- 1,655

- 4

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randn.html

So, assuming you're familiar with the normal distribution (Gaussian) you just need to choose an appropriate mean value, and standard deviation such that you virtually never encounter values outside of your desired range (i.e. setting the boundaries such that they lie at a very low probability). Recall that even at 1 standard deviation ([itex]\sigma=1[/itex]), you have 68% of your distribution, and that at ([itex]\sigma=3[/itex]) you have 99.7% of your values:

http://en.wikipedia.org/wiki/Normal_distribution#Standard_deviation_and_confidence_intervals

However, you'll still need to go through and set values which lie beyond the limits to your limits (e.g. -10.5 to -10). Why? That's left as an exercise to the reader, but consider how many values you'd expect to lie outside your limits if you set your limits at the ([itex]\sigma=3[/itex]) value, and you had 1000 values.

Yes Virginia, cumulative knowledge

- #3

- 590

- 0

how can i change the stadnard deviation from 1 to 3?

- #4

MATLABdude

Science Advisor

- 1,655

- 4

Look at the example in the documentation page for the randn function. And you still have to decide whether or not setting the standard deviation to 3 is acceptable! (As well, why 3 and 1/3 standard deviations to the boundaries?)how can i change the stadnard deviation from 1 to 3?

- Replies
- 1

- Views
- 3K

- Last Post

- Replies
- 7

- Views
- 15K

- Last Post

- Replies
- 1

- Views
- 4K

- Replies
- 0

- Views
- 4K

- Replies
- 3

- Views
- 8K

- Replies
- 1

- Views
- 2K

- Last Post

- Replies
- 10

- Views
- 1K

- Last Post

- Replies
- 3

- Views
- 2K

- Replies
- 11

- Views
- 8K

- Last Post

- Replies
- 4

- Views
- 274