Adding Rows with Specific Values to Existing Variables

조회 수: 2 (최근 30일)
balsip
balsip 2016년 10월 13일
댓글: Star Strider 2016년 10월 13일
Hello,
I have a 7x1 variable ("X1") to which I need to add a row at the beginning (cell value = 0) and a row at the end (cell value = 0). Obviously, I could do this manually, but I have many variables this needs to be done to.
My noodle is fried today. Apologies.

채택된 답변

Star Strider
Star Strider 2016년 10월 13일
편집: Star Strider 2016년 10월 13일
The easiest way is to concatenate zeros at the beginning and end of ‘X1’:
X1 = randi(9, 7, 1); % Create Data To Test Code
Result = [0; X1; 0];
  댓글 수: 3
James Tursa
James Tursa 2016년 10월 13일
편집: James Tursa 2016년 10월 13일
The X1 = randi(9, 7, 1) was just to get some sample data. You can eliminate that line since you already have X1 with your actual data. Just do this:
Result = [0; X1; 0];
Star Strider
Star Strider 2016년 10월 13일
Thank you, James!
Ambiguity now resolved (I hope).

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by