How to go row by row placing odd rows to Y values and even rows to X values

2 views (last 30 days)
I'm new to matlab and am struggling to even just start on a problem I am working on. Basically I have a user input a matrix. I then need to go row by row and have the even rows be Y coordinates and odd rows be X coordinates. I then plot those values. I have to use for loops to be able to repeatedly plot each new set of data. So for example the third and forth row would be a new set X and Y coordinates to be plotted. And thats where I am stuck at. I guess I don't fully understand for loops. Any help would be welcomed!

Answers (1)

Akira Agata
Akira Agata on 28 Mar 2019
How about the following?
% Create sample data (vector)
data = rand(1000,1);
% Extract odd and even rows, and save as x and y, respectively
x = data(1:2:end);
y = data(2:2:end);
% Visualize the result
figure
scatter(x,y)
xlabel('X')
ylabel('Y')
evenodd.png

Categories

Find more on Line Plots 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!