Related to vectors ?
3 ビュー (過去 30 日間)
古いコメントを表示
Hello all, I am working on a algorithm which is related to wireless communication wherein the source transmits signals to target.
These source and target are stored in two vectors as shown:
sr = [1,2,2,2,3,3,3,4,5]; % various possible source
ta = [2,3,6,8,6,4,7,6,6]; % various possible targets
So signal can be transmitted from 1st element of sr to 1st element of ta, 2nd element of sr to 2nd element of ta . Like wise from 9th element of sr to 9th element of ta.
My query is that how can we move between the elements of sr to elements of ta as I need to check whether the signal is transmitted or not.
2 件のコメント
John D'Errico
2023 年 5 月 5 日
You need to expain far more clearly the problem. What does "moving between the elements" mean here? Exactly what result would you expect to see from that example?
回答 (1 件)
Steven Lord
2023 年 5 月 5 日
As a guess, do you want to know if you can reach all the targets from one of the sources? You could use a graph object (assuming communication is bidirectional) or digraph (if it's one-way.)
sr = [1,2,2,2,3,3,3,4,5]; % various possible source
ta = [2,3,6,8,6,4,7,6,6]; % various possible targets
g = graph(sr, ta);
plot(g)
To tell if you can get there from here take a look at the distances function.
d = distances(g)
There are no Inf values in d so each node is reachable from each other node. If we were to delete the edge between 5 and 6:
g2 = rmedge(g, 5, 6);
plot(g2)
d2 = distances(g2)
5 is no longer reachable and so you see Inf values in d2 indicating that fact. There are other functions on graph objects that may also be of use (like conncomp) -- take a look at the graph documentation page and the section that contains that page for more information.
c = conncomp(g2, OutputForm = 'cell')
3 件のコメント
Steven Lord
2023 年 5 月 10 日
This is basic indexing.
sr = [1,2,2,2,3,3,3,4,5]; % various possible source
ta = [2,3,6,8,6,4,7,6,6]; % various possible targets
for whichElement = 1:numel(sr)
fprintf("Source %d goes to target %d.\n", sr(whichElement), ta(whichElement))
end
参考
カテゴリ
Help Center および File Exchange で Graph and Network Algorithms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!