User defined minimum Function

1 Ansicht (letzte 30 Tage)
Arpit Jain
Arpit Jain am 17 Mai 2019
Kommentiert: Walter Roberson am 26 Jun. 2021
How to create user defined function to create a vector of minimum values column wise from the input array argument?

Antworten (3)

Image Analyst
Image Analyst am 17 Mai 2019
Bearbeitet: Image Analyst am 17 Mai 2019
Try this:
function colMins = GetColumnMins(m) % m is a matrix
colMins = min(m, [], 1);
You can rename GetColumnMins, m, and colMins to (almost) whatever you want.

Walter Roberson
Walter Roberson am 17 Mai 2019
Bearbeitet: Walter Roberson am 17 Mai 2019
function mins = column_minima(input_array)
while any(any(diff(input_array,1,1) < 0))
input_array = shuffle_array(input_array);
end
mins = input_array(1,:);
function input_array = shuffle_array(input_array)
for col = 1 : size(input_array, 2)
input_array(:,col) = input_array( randperm(size(input_array,1)), col);
end
end
end
... confirmed working for 4 x 4 array.

Mostafa
Mostafa am 26 Jun. 2021
how can i create a function to calculate the minimum value at an array?
  2 Kommentare
Image Analyst
Image Analyst am 26 Jun. 2021
function result = MyMin(array)
result = min(array(:));
Walter Roberson
Walter Roberson am 26 Jun. 2021
My code above https://www.mathworks.com/matlabcentral/answers/462749-user-defined-minimum-function#answer_375560 calculates the minimum column-by-column value of arrays without using any built-in minimum function. It uses one of the official recognized sorting algorithms: https://en.wikipedia.org/wiki/Bogosort

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by