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

Illustration
Poppy - 2020-07-29T13:19:44+00:00
Question: How do I create a 2 column matrix from my x and y data

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); A(:,2)=y; A(:,1)=x;

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

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.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!