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)
Adog1(i,2*j-1:2*j) = [aik0_dog(i,1) bik0_dog(i,1)]
elseif BNdog(i) == blnmynokta(j)
Adog1(i,2*j-1:2*j) = [-aik0_dog(i,1) -bik0_dog(i,1)]
else
Adog1(i,2*j-1:2*j) = [0 0]
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.
ADOG=[0.289528073170415 0 0
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 Kommentare

John D'Errico
John D'Errico am 7 Apr. 2017
Bearbeitet: John D'Errico am 7 Apr. 2017
But we don't know what rule you want to use to build that matrix!
Yes, you got a somewhat different matrix from what you want. Learn to use the debugger. Look at the result from each line of code. Look where elements are being created. It looks like many of the elements are correct, but there are some extraneous elements that were created. So look at that.
Stephen23
Stephen23 am 8 Apr. 2017
If the code is wrong, then can you please provide a detailed explanation of what you want to calculate (i.e. the algorithm). But don't worry about the code itself: actually we know MATLAB reasonably well, but it does not help us if you provide us with broken code and don't tell us actually what you want it to do.
How are these numbers supposed to be calculated? In what order? Is there a general rule?
You desired output matrix is too complicated to know what the algorithm is just by looking at it, and broken code does not help us know the algorithm, so we need you to help us by explaining a bit more.
Muhendisleksi
Muhendisleksi am 8 Apr. 2017
1)
Muhendisleksi
Muhendisleksi am 8 Apr. 2017
2)
Muhendisleksi
Muhendisleksi am 8 Apr. 2017
3)
Muhendisleksi
Muhendisleksi am 8 Apr. 2017
4)
Muhendisleksi
Muhendisleksi am 8 Apr. 2017
Bearbeitet: Muhendisleksi am 8 Apr. 2017
Point number H
3 1016.253
2 1117.001
5 1047.644
6 1101.859
I tried to explain by visual. The "A" matrix is wrong. I wrote the matrix I found above.
I think the error:
Adog1(i,2*j-1:2*j)
I think I'm making mistakes here.
Geoff Hayes
Geoff Hayes am 8 Apr. 2017
Muhendisleksi - what are aik0_dog and bik0_dog?
Muhendisleksi
Muhendisleksi am 8 Apr. 2017
I typed wrong. It should be "aik0" and "aik0"

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 8 Apr. 2017

1 Stimme

Muhendisleksi - I think that you can simplify your code to populate Adog1 to be the following
Adog1 = zeros(length(DNdog),length(blnmynokta)); % pre-size Adog1
for i = 1:length(DNdog)
for j = 1:(length(blnmynokta))
if DNdog(i) == blnmynokta(j) % if the coefficient matches then put in Adog1
Adog1(i,j) = aik0(i);
end
if BNdog(i) == blnmynokta(j) % do the same comparison for BNdog
Adog1(i,j) = bik0(i);
end
end
end
Try the above and see what happens!

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 8 Apr. 2017

0 Stimmen

Adog1 = sum((reshape([DNdog,BNdog],[],1,2) == blnmynokta(:)').*cat(3,1,-1).*aik0,3);

Community Treasure Hunt

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

Start Hunting!

Translated by