Answers for "matlab if statement"

10

matlab if

for c = 1:ncols
    for r = 1:nrows
        
        if r == c
            A(r,c) = 2;
        elseif abs(r-c) == 1
            A(r,c) = -1;
        else
            A(r,c) = 0;
        end
        
    end
end
Posted by: Guest on August-27-2020
5

if statement in matlab

for c = 1:ncols
    for r = 1:nrows
        
        if r == c
            A(r,c) = 2;
        elseif abs(r-c) == 1
            A(r,c) = -1;
        else
            A(r,c) = 0;
        end
        
    end
end
A
Posted by: Guest on June-14-2020
2

matlab else if

if expression
    statements
elseif expression
    statements
else
    statements
end
Posted by: Guest on August-07-2020
1

matlab if statement

if r == c
  A(r,c) = 2;
elseif abs(r-c) ~= 1
  A(r,c) = -1;
else
  A(r,c) = 0;
end
Posted by: Guest on July-20-2020

Browse Popular Code Answers by Language