Combining a matrix with a null matrix

2 次查看(过去 30 天)
I have a very basic problem. I want to replace some entries of zero matrix with the elements of another non zero matrix. I tried with for loop by using conditional statements. But it didn't work.
x = [1 2 3 4], Y= [0 0 0 0 0 0 0 0 0 0]
desired output
z = [1 2 3 4 0 0 0 0 0 0]
So anyone please help. Thanks in advanced

采纳的回答

David Hill
David Hill 2020-9-1
z=Y;
z(1:length(x))=x;
  1 个评论
Arjun Upadhyay
Arjun Upadhyay 2020-9-3
I have done this with the the help of conditional statements and for loop. But this is quick and easy solution. Thank you.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by