How do I find the two smallest values in varargin?

1 visualización (últimos 30 días)
Harold Meggs
Harold Meggs el 24 de Abr. de 2015
Respondida: David Sanchez el 24 de Abr. de 2015
For example, the varargin input is 5,3,6
I want to multiply the the two lowest values, 5*3.
I have tried this:
y=sort (varargin,1, 'ascend');
z=y(:, 1:2);
area= z{1}*z{2};
This is the error I receive:
Error using sort
DIM and MODE arguments not supported for cell arrays.

Respuesta aceptada

David Sanchez
David Sanchez el 24 de Abr. de 2015
function out = two_lowest_values(varargin)
a = sort(cell2mat(varargin));
out = a(1)*a(2);

Más respuestas (1)

Harold Meggs
Harold Meggs el 24 de Abr. de 2015
I have also tried this:
Xs = sort(varargin);
min2nd = Xs{1,2};
minVal=min(varargin);
area=min2nd*minVal;
Error message:
Error using sort
Input argument must be a cell array of strings.

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by