How to correct for loop?

1 次查看(过去 30 天)
sarfse

采纳的回答

Andrei Bobrov
Andrei Bobrov 2016-8-25
编辑:Andrei Bobrov 2016-8-25
A = [ 1 0 0 4
1 0 3 4
1 2 0 4
1 2 3 4];
D = [ 0 22.2794 33.7859 45.0000
22.2794 0 15.4008 23.0367
33.7859 15.4008 0 14.9726
45.0000 23.0367 14.9726 0];
d = size(A);
B = nonzeros(A');
jj = [B(1:end-1),B(2:end)];
jj = jj(diff(jj,1,2) > 0,:);
k = cumsum([true;diff(jj(:,1))<=0]);
idx = sub2ind(d,jj(:,1),jj(:,2));
t = jj(:,1) == 1;
p = 50*t;
p(~t) = 180;
result = accumarray(k,D(idx).*p);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by