# Vectors and Elements - Matlab

Discussion in 'Programmer's Corner' started by Judas543, Mar 31, 2010.

1. ### Judas543 Thread Starter Member

Jan 26, 2010
60
0
• Write a single instruction of Matlab that will take a vector x and change it to y such that any element of x that is greater than 1 is set to y=1; every element of x less than -1 is set to y=-1; and for elements of x between -1 and +1 we have y=x. Test it on x, where “t=linspace(0,10,400)” and “x=2*sin(pi*t)”, and plot both x and y on the same axes.
I don't have a clue where to start... If someone could help me out that would be great!

• Write a single instruction of Matlab that will plot a histogram of 12000 sums each of 10 pairs of 5-sided die rolls. For instructions on the histogram function type “help hist”, and an example might be “hist(randn(1,1000))” to see what the histogram of a bunch of Gaussian random variables looks like (a bell curve).
This one was pretty easy
i just wrote this:
hist(sum(ceil(5*rand(12000,10)),2))

2. ### johndoe45 Member

Jan 30, 2010
364
1
we have done the first one before

"if" statements. i even attached a sample with a bunch of if statements

second one i'm guessing going to have to do 12000,2 in random function

x=1:12000

for i=length(x)
x(i)=4*rand(10,2)+1
end

x should be vector 1 to 12000 with 10 pairs of a 5 sided dice in each

that is a rough draft which should get you going

Last edited: Apr 2, 2010