Is there a way to apply multiple inputs to multiple functions?

2 views (last 30 days)
I am looking for a way to generate a matrix of results from applying 4 different functions to 5 input values. For example:
  • sin(x)
  • cos(x)
  • sqrt(x)
  • round(x)
Using:
  • x = 1.1
  • x = 1.6
  • x = 3.2
  • x = 4.7
  • x = 8.1
Is there any way to generate a 4x5 matrix with the results of each x-value applied to each function?

Accepted Answer

Joseph Cheng
Joseph Cheng on 30 Jul 2014
Edited: Joseph Cheng on 30 Jul 2014
yeah, its very simple, if you go
x = [1.1 1.6 3.2 4.7 8.1]
if you played around with it, then you'd figure out that if you stick x, as a matrix, in each of those functions you'll see that the function is applied to each value in x.
so we can then do something like this to concatenate it.
result = [sin(x);cos(x);sqrt(x);round(x)];
where you'll then get a 4x5 matrix with the first row being sin and the last round.
since i've done 90% of the work there. i'll let you figure out how to write a function.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!