Effacer les filtres
Effacer les filtres

how to join two matrices ??

1 vue (au cours des 30 derniers jours)
Mamali
Mamali le 31 Mai 2014
Commenté : Star Strider le 1 Juin 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

Réponse acceptée

Star Strider
Star Strider le 31 Mai 2014
Modifié(e) : Star Strider le 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 commentaires
Mamali
Mamali le 1 Juin 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 le 1 Juin 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by