# I make mistakes while creating a matrix

조회 수: 1 (최근 30일)
Muhendisleksi 2017년 4월 7일
답변: Andrei Bobrov 2017년 4월 8일
DNdog =[2;2;2;3;3;3;5;5]
BNdog =[3;5;6;2;5;6;2;3]
blnmynokta =[2;5;6]
aik0 =[0.289528073170415
0.330368386539138
0.339433756993357
0.289527607389207
0.407152568064959
0.424260572052654
0.330366215572373
0.407154361068522]
bik0 =[-0.289528073170415
-0.330368386539138
-0.339433756993357
-0.289527607389207
-0.407152568064959
-0.424260572052654
-0.330366215572373
-0.407154361068522]
for i = 1:length(DNdog)
for j = 1:(length(blnmynokta))
if DNdog(i) == blnmynokta(j)
elseif BNdog(i) == blnmynokta(j)
else
end
end
end
% This is the resulting matrix
Adog1=[0.289528073170415 -0.289528073170415 0 0 0 0
0.330368386539138 -0.330368386539138 -0.330368386539138 0.330368386539138 0 0
0.339433756993358 -0.339433756993358 0 0 -0.339433756993358 0.339433756993358
-0.289527607389207 0.289527607389207 0 0 0 0
0 0 -0.407152568064959 0.407152568064959 0 0
0 0 0 0 -0.424260572052654 0.424260572052654
-0.330366215572373 0.330366215572373 0.330366215572373 -0.330366215572373 0 0
0 0 0.407154361068522 -0.407154361068522 0 0]
% This is the matrix I have to find. But I could not.
0.330368386539138 -0.330368386539138 0
0.339433756993358 0 -0.339433756993358
-0.289527607389207 0 0
0 -0.407152568064959 0
0 0 -0.424260572052654
-0.330366215572373 0.330366215572373 0
0 0.407154361068522 0]
##### 댓글 수: 9이전 댓글 7개 표시이전 댓글 7개 숨기기
Geoff Hayes 2017년 4월 8일
Muhendisleksi - what are aik0_dog and bik0_dog?
Muhendisleksi 2017년 4월 8일
I typed wrong. It should be "aik0" and "aik0"

댓글을 달려면 로그인하십시오.

### 채택된 답변

Geoff Hayes 2017년 4월 8일
Muhendisleksi - I think that you can simplify your code to populate Adog1 to be the following
for i = 1:length(DNdog)
for j = 1:(length(blnmynokta))
if DNdog(i) == blnmynokta(j) % if the coefficient matches then put in Adog1
end
if BNdog(i) == blnmynokta(j) % do the same comparison for BNdog
end
end
end
Try the above and see what happens!
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Muhendisleksi 2017년 4월 8일
Thank you very, very much!

댓글을 달려면 로그인하십시오.

### 추가 답변 (1개)

Andrei Bobrov 2017년 4월 8일

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by