MATLAB Answers

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

Asked by Kelly Penland

### Kelly Penland (view profile)

on 27 Mar 2019
Latest activity Answered by Akira Agata

### Akira Agata (view profile)

on 28 Mar 2019
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!

#### 0 Comments

Sign in to comment.

## 1 Answer

### Akira Agata (view profile)

Answer by Akira Agata

### Akira Agata (view profile)

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')

#### 0 Comments

Sign in to comment.