I see that I can define a range with 1:3
. I can also apply a function to a number, e.g. sin(1)
. But, how do I map the range of numbers with the function? I would like to $1,2,3 \to sin(1), sin(2), sin(3)$.
Asked
Active
Viewed 52 times
-1

Valentin Tihomirov
- 1
- 1
- 6
- 28
-
1You can't use that type of markdown on SO. Use backtick for code formatting. I don't understand the question... Can you try to explain it better? Do you want `sin(1:3)`? Can you please accurately explain what you want to achieve? – Stewie Griffin Apr 20 '16 at 09:22
1 Answers
1
I suspect you want something like this:
[1:n; sin(1:n)].'
ans =
1.0000 0.8415
2.0000 0.9093
3.0000 0.1411
4.0000 -0.7568
or
f = @(n) sin(n)
f(1:n)
ans =
0.8415 0.9093 0.1411 -0.7568
I can explain it more thoroughly if you confirm that this is what you want to achieve.

Stewie Griffin
- 14,889
- 11
- 39
- 70