How do i combine two different sized vectors?
显示 更早的评论
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]
采纳的回答
更多回答(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 个评论
Andrei Bobrov
2017-11-15
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
2017-11-15
@Andrei: Yes. I assume the shown data match to setting the Y values in the first line - perhaps.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!