how can i make a general matrix?
1 次查看(过去 30 天)
显示 更早的评论
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
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.
采纳的回答
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
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!