I can not create a matrix.

4 views (last 30 days)
Muhendisleksi
Muhendisleksi on 5 May 2017
Edited: Honglei Chen on 5 May 2017
a =[ 7
7
7
11
11
11]
b =[ 4
4
4
4
4
4]
c =[11
11
11]
d =[ 4
4
4
7
7
7]
for i = 1:length(a)
for j = 1:(length(c))
if (b(i) == d(j))
A(i,j) = [0]
elseif (a(i) == c(j))
A(j,j) = [-1]
end
end
end
A = [0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0] % This matrix is forming.
% The matrix to form:
A = [0 0 0
0 0 0
0 0 0
-1 0 0
0 -1 0
0 0 -1]

Answers (1)

Honglei Chen
Honglei Chen on 5 May 2017
I don't know what your logic is but the code is behaving as expected. The first condition (b(i)==c(j)) is always satisfied so the second branch is never executed.
HTH
  2 Comments
Muhendisleksi
Muhendisleksi on 5 May 2017
Edited: Muhendisleksi on 5 May 2017
I was trying to create this matrix.
Honglei Chen
Honglei Chen on 5 May 2017
Edited: Honglei Chen on 5 May 2017
If the matrix is constant, what's wrong just typing is out, say
A = [zeros(3);-1*eye(3)]

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!