How do i combine two different sized vectors?
Mostrar comentarios más antiguos
A = [1;3;5;7;9;11] and B = [2;4;6;8;10;12;14;16]
to make C = [1;2;3;4;5;6;7;8;9;10;11;12;14;16]
Respuesta aceptada
Más respuestas (1)
It is possible. Assuming, that you data do not contain NaNs:
X1 = [3;2;1;-1;2;3];
Y1 = [3.5;2.5;1.5;-1.5;2.5;3.5];
function C = JoinWithOrder(X, Y)
nX = numel(X);
nY = numel(Y);
C = NaN(2, max(nX, nY));
C(1, 1:nY) = Y(:).';
C(2, 1:nX) = X(:).'; % [EDITED, "C(1" -> "C(2", thanks Andrei!
C = C(~isnan(C));
end
2 comentarios
Andrei Bobrov
el 15 de Nov. de 2017
Hi Jan! Maybe so?
C(1, 1:nY) = Y(:).';
C(2, 1:nX) = X(:).';
or
C(2, 1:nY) = Y(:).';
C(1, 1:nX) = X(:).';
Jan
el 15 de Nov. de 2017
@Andrei: Yes. I assume the shown data match to setting the Y values in the first line - perhaps.
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!