Is there a way to apply multiple inputs to multiple functions?
조회 수: 1 (최근 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?
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!