MATLAB Answers

how can ı find min value using for loop in matrice

59 views (last 30 days)
sarp karayegen
sarp karayegen on 23 Apr 2020
Commented: Deepak Gupta on 23 Apr 2020
[1:100] matrice

  0 Comments

Sign in to comment.

Answers (2)

Deepak Gupta
Deepak Gupta on 23 Apr 2020
Edited: Deepak Gupta on 23 Apr 2020
You really don't need to use for loop in matlab to find min term.
If you have a matrix A, then min(A) will give you minimum value in matrix.

  1 Comment

Deepak Gupta
Deepak Gupta on 23 Apr 2020
If you really need for loop then:
minTerm = A(1, 1);
for i= 1:size(A, 1)
for j = 1:size(A, 2)
if(A(i, j)<minTerm)
minTerm = A(i, j);
end
end
end

Sign in to comment.


Prasad Reddy
Prasad Reddy on 23 Apr 2020
clc
clear all
A=[2,4,5,7,4,3,5,6] % creating our required vector
l=length(A) % finding the length of our vector
min=A(1); % assain the first value of our vector to min
for i=1:1:l
if A(i)<min % from then onwards check each element and
min=A(i) % if the element is less than the value stored in min
end % assain new value
end
min

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!