필터 지우기
필터 지우기

copying arrays from one variable to another .

조회 수: 72 (최근 30일)
Pradeep Gowda
Pradeep Gowda 2015년 4월 5일
댓글: Kelsey Romine 2017년 9월 12일
i have 2 variables, a=[22 23 43 0 0 0 0], now i need to copy array ' a ' to ' b ' from 1st element to 3rd element. how can it be done?? i tried b=a(3); , b=a(:,3), all these copies only that corresponding element.

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 4월 5일
Pradeep - if you want to copy the first three elements of a into b, then just do
a = [22 23 43 0 0 0 0];
b = a(:,1:3);
In the above, since a is a row vector, we want to copy the first three elements (columns) of a. Try it and see what happens!
  댓글 수: 2
Kelsey Romine
Kelsey Romine 2017년 9월 12일
What if I need the first two elements and the fourth and fifth elements?
Kelsey Romine
Kelsey Romine 2017년 9월 12일
Never mind. I figured it out: b = a(:, [1:2, 3:4]);

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

추가 답변 (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