User defined minimum Function

1 次查看(过去 30 天)
Arpit Jain
Arpit Jain 2019-5-17
How to create user defined function to create a vector of minimum values column wise from the input array argument?

回答(3 个)

Image Analyst
Image Analyst 2019-5-17
编辑:Image Analyst 2019-5-17
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 2019-5-17
编辑:Walter Roberson 2019-5-17
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 2021-6-26
how can i create a function to calculate the minimum value at an array?
  2 个评论
Walter Roberson
Walter Roberson 2021-6-26
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by