what is the form of the matrix B

A=[1 2 3 ;4 5 6; 7 8 9]
For i=1 size:(A,1)
For j=1 size:(A,2)
If j==1
B(i,j)=A(i,j);
else if j<i
B(i,j)=A(i,j)+1;
else if
B(i,j)=A(i,j)-1;
end
end

Answers (3)

There some errors in your code
A=[1 2 3 ;4 5 6; 7 8 9]
for i=1:size(A,1)
for j=1:size(A,2)
if j==1
B(i,j)=A(i,j);
else if j<i
B(i,j)=A(i,j)+1;
else
B(i,j)=A(i,j)-1;
end
end
end
end

2 Comments

yes the code is like this so what s the form of the matrix b?

Sign in to comment.

Walter Roberson
Walter Roberson on 11 Sep 2013
B is a 3 x 3 numeric matrix.

2 Comments

what are the elements of B
After you view this short video http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ you will learn how to find out.

Sign in to comment.

The answer
disp(B)
is such trivial, that I hesitate to believe that it solves the problem.

Asked:

on 11 Sep 2013

Community Treasure Hunt

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

Start Hunting!