Info

この質問は閉じられています。 編集または回答するには再度開いてください。

distribute list to Matrices

1 回表示 (過去 30 日間)
tevzia
tevzia 2013 年 10 月 15 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi,
I have a list that shows distances of the points. It is like
Point A, Point B 5.2
Point A, Point C 4.3
Point A, Point D 2.1
Point B, Point C 7.6
Point B, Point D 3.3
Point C, Point D 1.2
But i want to recreate a matrices with that list like
Point A Point B Point C Point D
Point A 0 5.2 4.3 2.1
Point B 5.2 0 7.6 3.3
Point C 4.3 7.6 0 1.2
Point D 2.1 3.3 1.2 0
Is it possible to do it in Matlab
  3 件のコメント
tevzia
tevzia 2013 年 10 月 15 日
yes its a cell array. Actually it is a dat(text) file (excell file) and i need convert it to use if its possible. i will use those point to create a minimum spanning tree algorithm. Here is the minimum spanning tree function:
function A = minimum_spanning_tree(C1, C2)
%
% Find the minimum spanning tree using Prim's algorithm.
% C1(i,j) is the primary cost of connecting i to j.
% C2(i,j) is the (optional) secondary cost of connecting i to j, used to break ties.
% We assume that absent edges have 0 cost.
% To find the maximum spanning tree, used -1*C.
% We partition the nodes into those in U and those not in U.
% closest(i) is the vertex in U that is closest to i in V-U.
% lowcost(i) is the cost of the edge (i, closest(i)), or infinity is i has been used.
% In Aho, they say C(i,j) should be "some appropriate large value" if the edge is missing.
% We set it to infinity.
% However, since lowcost is initialized from C, we must distinguish absent edges from used nodes.
n = length(C1);
if nargin==1, C2 = zeros(n); end
A = zeros(n);
closest = ones(1,n);
used = zeros(1,n); % contains the members of U
used(1) = 1; % start with node 1
C1(find(C1==0))=inf;
C2(find(C2==0))=inf;
lowcost1 = C1(1,:);
lowcost2 = C2(1,:);
for i=2:n
ks = find(lowcost1==min(lowcost1));
k = ks(argmin(lowcost2(ks)));
A(k, closest(k)) = 1;
A(closest(k), k) = 1;
lowcost1(k) = inf;
lowcost2(k) = inf;
used(k) = 1;
NU = find(used==0);
for ji=1:length(NU)
for j=NU(ji)
if C1(k,j) < lowcost1(j)
lowcost1(j) = C1(k,j);
lowcost2(j) = C2(k,j);
closest(j) = k;
end
end
end
end
so C1 is going to be distance between point A and point B and so on.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 15 日
編集済み: Azzi Abdelmalek 2013 年 10 月 15 日
Is it like this?
A={'Point A,' 'Point B' '5.2'; 'Point A,' 'Point C' '4.3'}

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by