Is there a way to combine two variables?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jack Smillie
am 1 Mai 2019
Beantwortet: Guillaume
am 1 Mai 2019
I want combine two variables so that I can use it with the command 'patch' to create multiple rectangles which apparently has to have a matrix of x by 2 for each coordinate. So essentially what I want to do is this (this isn't the actual code I have, it's just visually what I want to happen if it's possible):
A=1 2 3 4 B= 8 7 6 5
5 6 7 8 4 3 2 1
AB= (1 8)
(2 7)
(3 6)
(4 5)
(5 4)
(6 3)
(7 2)
(8 1)
Is it possible to do that and then convert it into a matrix so it's useable by 'patch'?
0 Kommentare
Akzeptierte Antwort
Guillaume
am 1 Mai 2019
If the order in AB is not critical, as long as elements of A are matched with elements of B:
AB = [A(:), B(:)];
If you absolutely need to have the order you specify:
AB = [reshape(A.', [], 1), reshape(B.', [], 1)];
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Polygons 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!