MATLAB Answers

How do I create a 2 column matrix from my x and y data

407 views (last 30 days)
James Bagnall
James Bagnall on 25 Aug 2019
Commented: Sara Fawal on 25 Jun 2020
I want to make a 2 column matrix for my x and y data which consists of 1000 datapoints, I have tried this and it replaces only one column:
x=[0 1 2 3 4 5];
y=[0 1 2 3 4 5];
A = zeros(1000,2);

Accepted Answer

Star Strider
Star Strider on 25 Aug 2019
Your data as you posted them are row vectors. Create column vectors from them to create ‘A’ by either doing a simple transpose (use the .' operator, not '), or forcing them to be column vectors with the ‘(:)’ notation
Try this:
A = [x(:), y(:)]
That should work.
Sara Fawal
Sara Fawal on 25 Jun 2020
Hello Star How can I apply your code in a loop for multiple parameters?
My 'X' vector is my time variable and does not change.
However the 'Y' vectors are my changing variables.
Ex: X= time
Please let me know. Thank you

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by