Anonymous Function Array Output

조회 수: 18 (최근 30일)
Zhuoyi Chen
Zhuoyi Chen 2017년 10월 26일
답변: Ryan Miller 2019년 2월 4일
Write a script that contains an anonymous function min_max to find the minimum and the maximum of an array. The output should be returned as a 1D array. The first value contains the minimum, and the second the maximum. The function should make use of internal functions.
  댓글 수: 6
OCDER
OCDER 2017년 10월 26일
Based on the assert tests, it wants:
y = min_max(x)
where
y(1) = minimum of x
y(2) = maximum of x
Zhuoyi Chen
Zhuoyi Chen 2017년 10월 26일
Yeah, but I don't know how to output an array like that, I mean, using the anonymous function.

댓글을 달려면 로그인하십시오.

답변 (2개)

Honglei Chen
Honglei Chen 2017년 10월 26일
You are returning two separate outputs, the instruction says "The output should be returned as a 1D array"
HTH
  댓글 수: 2
Zhuoyi Chen
Zhuoyi Chen 2017년 10월 26일
emmmmmmmm... so what should I do then?
Honglei Chen
Honglei Chen 2017년 10월 27일
right now you are using deal to separate the outputs into two. What you need to do is instead of that, putting them into an array. for example, [1 2] will be an array consisting of two elements.

댓글을 달려면 로그인하십시오.


Ryan Miller
Ryan Miller 2019년 2월 4일
% Your code goes here
min_max = @(A) [min(A), max(A)];
%define random array A
A = rand(1,10);
%display minimum and maximum
disp(min(A));
disp(max(A));

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by