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

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Joseph Cheng
Joseph Cheng am 30 Jul. 2014
Bearbeitet: Joseph Cheng am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by