Anonymous Function Array Output

15 visualizzazioni (ultimi 30 giorni)
Zhuoyi Chen
Zhuoyi Chen il 26 Ott 2017
Risposto: Ryan Miller il 4 Feb 2019
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 Commenti
OCDER
OCDER il 26 Ott 2017
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 il 26 Ott 2017
Yeah, but I don't know how to output an array like that, I mean, using the anonymous function.

Accedi per commentare.

Risposte (2)

Honglei Chen
Honglei Chen il 26 Ott 2017
You are returning two separate outputs, the instruction says "The output should be returned as a 1D array"
HTH
  2 Commenti
Zhuoyi Chen
Zhuoyi Chen il 26 Ott 2017
emmmmmmmm... so what should I do then?
Honglei Chen
Honglei Chen il 27 Ott 2017
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.

Accedi per commentare.


Ryan Miller
Ryan Miller il 4 Feb 2019
% 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));

Categorie

Scopri di più su Performance and Memory in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by