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

1 回表示 (過去 30 日間)
Giorgia
Giorgia 2014 年 7 月 30 日
編集済み: Joseph Cheng 2014 年 7 月 30 日
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?

採用された回答

Joseph Cheng
Joseph Cheng 2014 年 7 月 30 日
編集済み: Joseph Cheng 2014 年 7 月 30 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by