MATLAB Answers


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

Asked by James Bagnall on 25 Aug 2019 at 0:39
Latest activity Commented on by Star Strider
on 25 Aug 2019 at 0:52
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);


Sign in to comment.

1 Answer

Answer by Star Strider
on 25 Aug 2019 at 0:45
 Accepted Answer

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.


Yes that works just wasnt sure about the notation, thanks for the help
As always, my pleasure!

Sign in to comment.