Adding two matrix together

조회 수: 2 (최근 30일)
Cside
Cside 2019년 10월 13일
댓글: Star Strider 2019년 10월 13일
Hi, I have 2 matrix, A (1 x 30) and B (1x60). in B, the numbers from cells 1-30 are zeros and I would like to replace A into the first 30 cells of B, having an end result of 1x60 double.
How may I do that?
Thank you!

채택된 답변

Star Strider
Star Strider 2019년 10월 13일
Try this:
A = rand(1,30); % Create Vector
B = [zeros(1,30) rand(1,30)]; % Create Vector
B(1:30) = A; % Desired Result
You did not mention testing for the zero values, or if any other elements of ‘B’ were zero.
  댓글 수: 5
Cside
Cside 2019년 10월 13일
i think i got it. Thanks!
Star Strider
Star Strider 2019년 10월 13일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by