how can i make a general matrix?

조회 수: 3 (최근 30일)
arian hoseini
arian hoseini 2022년 1월 8일
댓글: arian hoseini 2022년 1월 9일
i asked this question many times but still have a problem....someone help me please i need answer as soon as possible...
  댓글 수: 2
John D'Errico
John D'Errico 2022년 1월 8일
편집: John D'Errico 2022년 1월 8일
I see you still have problem. However, the issue is you need to EXPLAIN clearly what you need. If you cannot explain what your goal is, how can you expect help?
Is this matrix symmetric? That is, is it true that x(i,j) == x(j,i) always? The rule for x12 that you show would seem to say that is true.
Would x(2,2) be the sum of 5 elements? Thus... sum(L([1 4 5 6 7],4))?
Finally, it really helps if you post actual code, rather than a PICTURE of code. For example, while I can look at the matrix L, I cannot paste it into MATLAB.
arian hoseini
arian hoseini 2022년 1월 8일
thats on me and im sorry for my explanation
L =[1 2 0.1 0.2 0.02
1 4 0.05 0.2 0.02
1 5 0.08 0.3 0.03
2 3 0.05 0.25 0.03
2 4 0.05 0.1 0.01
2 5 0.1 0.3 0.02
2 6 0.07 0.2 0.025
3 5 0.12 0.26 0.025
3 6 0.02 0.1 0.01
4 5 0.2 0.4 0.04
5 6 0.1 0.3 0.03]
%-------------------------------Program strat her--------------------------
nl = L(:,1); nr = L(:,2); R = L(:,3);
X = L(:,4); Bc = j*L(:,5);
nbr=length(L(:,1)); nbus = max(max(nl), max(nr));

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

채택된 답변

Torsten
Torsten 2022년 1월 8일
편집: Torsten 2022년 1월 8일
function main
L = [1 2 0.1 0.2 0.02; ...
1 4 0.05 0.2 0.02; ...
1 5 0.08 0.3 0.03; ...
2 3 0.05 0.25 0.03; ...
2 4 0.05 0.1 0.01; ...
2 5 0.1 0.3 0.02; ...
2 6 0.07 0.2 0.025; ...
3 5 0.12 0.26 0.025; ...
3 6 0.02 0.1 0.01; ...
4 5 0.2 0.4 0.04; ...
5 6 0.1 0.3 0.03];
nl = L(:,1);
nr = L(:,2);
x = L(:,4);
n = numel(x);
Nb = 6;
mat = zeros(Nb,Nb);
n = numel(x);
for i = 1:Nb
for j = 1:Nb
logic = zeros(n,1);
if i==j
for k = 1:n
logic(k) = nl(k)==i || nr(k)==i;
end
else
for k = 1:n
logic(k) = (nl(k)==i && nr(k) ==j) || (nl(k)==j && nr(k)==i);
end
end
mat(i,j) = sum(x(logic==1));
end
end
mat
end
  댓글 수: 3
Torsten
Torsten 2022년 1월 8일
Corrected.
arian hoseini
arian hoseini 2022년 1월 9일
thank u so much.

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

추가 답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 1월 8일
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2022년 1월 8일
That's not really how Answers works.
arian hoseini
arian hoseini 2022년 1월 8일
x = zeros(Nb);
for i=1:Nb
for j=1:Nb
rowsToSum = L(:,1) == i & L(:,2) == j;
x(i,j) = sum(L(rowsToSum, 4));
end
end
disp(x)
i dont expect you to write the whole code for me so help me with this...i tried the top code but i get this
0 0.2000 0 0.2000 0.3000 0
0 0 0.2500 0.1000 0.3000 0.2000
0 0 0 0 0.2600 0.1000
0 0 0 0 0.4000 0
0 0 0 0 0 0.3000
0 0 0 0 0 0
for x11 i added this % x(i) = sum(L(rowsToSum, 4));
but still not working and as you see x21 should be like x12 but...the others are like this too

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by