User defined minimum Function

조회 수: 1 (최근 30일)
Arpit Jain
Arpit Jain 2019년 5월 17일
댓글: Walter Roberson 2021년 6월 26일
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
Image Analyst
Image Analyst 2021년 6월 26일
function result = MyMin(array)
result = min(array(:));
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