Info

この質問は閉じられています。 編集または回答するには再度開いてください。

The for loop does not give the result I want.

1 回表示 (過去 30 日間)
Muhendisleksi
Muhendisleksi 2017 年 5 月 26 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
DNdog =
7
7
7
11
11
11
blnmynokta =
11
11
11
ksnkoor =
4
4
4
7
7
7
for i = 1:length(DNdog)
for j = 1:(length(blnmynokta))
if (DNdog(i) == ksnkoor(j))
A(i,j) = [0]
elseif (DNdog(i) == blnmynokta(j))
A(j,j) = [-1]
end
end
end
Formed matrix:
A =
-1 0 0
0 -1 0
0 0 -1
The matrix I want to form:
A=
0 0 0
0 0 0
0 0 0
-1 0 0
0 -1 0
0 0 -1
I do not understand where I made mistakes. Can you help me?

回答 (1 件)

GEEVARGHESE TITUS
GEEVARGHESE TITUS 2017 年 5 月 26 日
The index of A was wrong
clc
clear all
close all
DNdog =[7;7;7;11;11;11];
blnmynokta =[11;11;11]
ksnkoor =[4;4;4;7;7;7]
for i = 1:length(DNdog)
for j = 1:(length(blnmynokta))
if (DNdog(i) == ksnkoor(j))
A(i,j) = [0]
elseif (DNdog(i) == blnmynokta(j))
A(i,j) = [-1]
end
end
end
  1 件のコメント
Muhendisleksi
Muhendisleksi 2017 年 5 月 26 日
Wrong result:
A =
0 0 0
0 0 0
0 0 0
-1 -1 -1
-1 -1 -1
-1 -1 -1

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by