Clear Filters
Clear Filters

how to join two matrices ??

1 view (last 30 days)
Mamali
Mamali on 31 May 2014
Commented: Star Strider on 1 Jun 2014
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

Accepted Answer

Star Strider
Star Strider on 31 May 2014
Edited: Star Strider on 31 May 2014
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 Comments
Mamali
Mamali on 1 Jun 2014
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 on 1 Jun 2014
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!