Filter löschen
Filter löschen

how to join two matrices ??

1 Ansicht (letzte 30 Tage)
Mamali
Mamali am 31 Mai 2014
Kommentiert: Star Strider am 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

Akzeptierte Antwort

Star Strider
Star Strider am 31 Mai 2014
Bearbeitet: Star Strider am 31 Mai 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 Kommentare
Mamali
Mamali am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by