how to insert value of array to other array
4 次查看(过去 30 天)
显示 更早的评论
hi guys
i have array
rr=[1,2,3,4,5]
i want to insert
y=[5,6,1]
on it to be
rr=[1,2,3,4,5,5,6,1]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
the second question insert one element not array
for example
y=2;
rr=[1,2,3,4,5]
rr=[1,2,3,4,5,2]
0 个评论
采纳的回答
Walter Roberson
2020-5-26
horzcat(). [list of values] is also horzcat()
2 个评论
Walter Roberson
2020-5-27
y=2
rr=[1,2,3,4,5]
horzcat(rr,y)
y =
2
rr =
1 2 3 4 5
ans =
1 2 3 4 5 2
Note that this requires that your inputs are both row vectors -- or at least that whatever they are has the same number of rows.
If you are adding new rows to an array see vertcat(), which requires that whatever the inputs are has the same number of columns as each other.
If you do not know ahead of time whether the inputs are row vectors or column vectors or that they are the same as each other , then provided they are both vectors, you can use
newrr = rr;
newrr(end+length(y)) = y;
This will have the same orientation as rr has.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!