MATLAB Answers

Matrix 'if' statement

8 views (last 30 days)
Eva Carrillo
Eva Carrillo on 2 Dec 2019
Edited: KALYAN ACHARJYA on 2 Dec 2019
I just learned how to do matrices today, and am quite confused on this problem. So I have to create a 100 x 100 matrix. Every spot in the matrix takes on the value , where i represents the row and j represents the column location. I have a formula in which the value K is defined as the greater value of i and j. I need to create an if loop that compares the row and column position values and chooses the larger of the two, then defines that as the variable K.
I don't know what kind of syntax to use in terms of matrices. I know how to build an if staement, but am jsut simply confused on the kind of matlab syntax that needs to be followed.
  1 Comment
KALYAN ACHARJYA
KALYAN ACHARJYA on 2 Dec 2019
%create matrics
[r c]=size(matrix); % find row and col number, If not known already
for i=1:r
for j=1:c
if condition
matrix(i,j)=...
end
end
end
You can do same without loop also. Being as beginer atleast you should learn how to use loop to do iteration on 1D or 2D array
Welcome to Matlab World! Please try and try, you can. We are here to help you!
Happy Learning & Good Luck!
:)

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!