Combining a matrix with a null matrix

조회 수: 1 (최근 30일)
Arjun Upadhyay
Arjun Upadhyay 2020년 9월 1일
댓글: Arjun Upadhyay 2020년 9월 3일
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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by