Add element to a given vector
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
steve Brian
am 10 Apr. 2020
Kommentiert: steve Brian
am 10 Apr. 2020
I have a vector of the format:
x = [X1 X2 … Xn]
I want to add an element to the end, X(n+1). How do I do that?
x = [ X1 X2 .. Xn X(n+1) ]
ex: x = [ 1 4 2 8]
newX = [ 1 4 2 8 9]
A little help, please!
0 Kommentare
Akzeptierte Antwort
per isakson
am 10 Apr. 2020
Bearbeitet: per isakson
am 10 Apr. 2020
One way
>> x = 1:6
x =
1 2 3 4 5 6
>> x(end+1)=17
x =
1 2 3 4 5 6 17
>>
5 Kommentare
per isakson
am 10 Apr. 2020
I'm even more confused
"I have already the newV, but i want to add that n+1 element"
Isn't that exactly what's done by
NewV(end+1) = 22;
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!