how to join two matrices ??

1 次查看(过去 30 天)
Hello everyone, I have got two matrices(path & path1) and want to put these two together in a way that I get path 3
path =
Columns 1 through 13
14 9 5 2 1 0 0 0 0 0 0 0 0
path1 :
1 2 5 9 14 0 0 0 0 0 0 0 0
1 2 5 9 15 0 0 0 0 0 0 0 0
1 2 5 10 16 0 0 0 0 0 0 0 0
1 3 7 11 17 0 0 0 0 0 0 0 0
1 3 7 12 18 0 0 0 0 0 0 0 0
1 4 8 13 19 0 0 0 0 0 0 0 0
Columns 14 through 19
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Path 3:
14 9 5 2 1 2 5 9 14 0 0 0 0
14 9 5 2 1 2 5 9 15 0 0 0 0
14 9 5 2 1 2 5 10 16 0 0 0 0
14 9 5 2 1 3 7 11 17 0 0 0 0
14 9 5 2 1 13 7 12 18 0 0 0 0
14 9 5 2 1 4 8 13 19 0 0 0 0
Columns 14 through 19
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

采纳的回答

Star Strider
Star Strider 2014-5-31
编辑:Star Strider 2014-5-31
If I understand correctly what you want to do, this will work:
path = path(path>0);
path3 = circshift(path1, [0 size(path,2)-1]);
path3(:,5) = 0;
pathm = [repmat(path, size(path1,1), 1)...
zeros(size(path1,1),size(path1,2)-size(path,2))];
path3 = path3 + pathm
( EDIT: slight reformat to add ‘...’ to make it fit in the window without ambiguity. )
  6 个评论
Mamali
Mamali 2014-6-1
I really appreciate your advice, to put it in nutshells ,I am trying to build routes between nodes through a specific node which is 1.
I need to make 3 on the first Iteration , 4 on the second , 5 on the third (meaning the third dimension need to be capped in advance). The routes are calculated once from node 14 to 1 and the other time from 1 to the rest (and the source changes and so on...). I will certainly appreciate your advice as I proceed forward and will post on here.
Star Strider
Star Strider 2014-6-1
This sounds like graph theory, which unfortunately is not an area of my expertise. I will do what I can to help with the MATLAB code, but cannot promise help on the underlying concepts.

请先登录,再进行评论。

更多回答(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