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일

1 개 추천

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일
other elements in B are not 0, but it does contain some Nan. will try!
Cside
Cside 2019년 10월 13일
hmm the numbers seem bit wonky. My A is 1x33 and B is 1x61 but the B was returned to be 1 x 66. Is there a reason why?
*The first 1-33 cells in B were 0s.
Star Strider
Star Strider 2019년 10월 13일
In the example you posted, ‘B’ remains (1x60), after the substitution of the first 30 elements.
My A is 1x33 and B is 1x61 but the B was returned to be 1 x 66. Is there a reason why? The first 1-33 cells in B were 0s
I have no idea what the reason is. I don’t have your actual ‘A’ and ‘B’, or the code you used.
Cside
Cside 2019년 10월 13일
i think i got it. Thanks!
Star Strider
Star Strider 2019년 10월 13일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2019년 10월 13일

댓글:

2019년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by