copying arrays from one variable to another .

123 Ansichten (letzte 30 Tage)
Pradeep Gowda
Pradeep Gowda am 5 Apr. 2015
Kommentiert: Kelsey Romine am 12 Sep. 2017
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.

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 5 Apr. 2015
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 Kommentare
Kelsey Romine
Kelsey Romine am 12 Sep. 2017
What if I need the first two elements and the fourth and fifth elements?
Kelsey Romine
Kelsey Romine am 12 Sep. 2017
Never mind. I figured it out: b = a(:, [1:2, 3:4]);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by