Add SINGLE element to array or vector
Show older comments
I have a vector of the format:
x = [xval(1) xval(2) … xval(n)]
, and I want to add an element to the end, xval(n+1). How do I do that?
1 Comment
Image Analyst
on 27 May 2022
@Anushalini Thiyagarajan I have no idea what you mean. Please ask your question in a new question (not here) after you read this:
In the meantime, look at input functions such as readmatrix, importdata, dlmread, xlsread, fgetl, etc.
Accepted Answer
More Answers (2)
Dakota Jandek
on 7 Apr 2020
2 votes
x = [1, 2, 3]
x(length(x)+1) = 4
2 Comments
Adrien Bouguerra
on 18 Oct 2020
amazing method , really efficient thank u so much Dakota
Image Analyst
on 18 Oct 2020
Or even better,
x = [1, 2, 3]
x(end+1) = 4
Youssef AAKAM
on 13 Oct 2019
1 vote
x=[]
x=[x;'ysf']
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!