# divide row and plot it

1 view (last 30 days)
abdullah al-dulaimi on 6 Dec 2022
Answered: KSSV on 6 Dec 2022
I have this data,
data=[1 2 3 1 2 3; 7 8 9 10 11 12]
, the data consist of 2 columns, So i want to take a for loop for i = 1:3:end , and then plot it. So after the loop, the result will be,
1 7 and 1 10
2 8 2 11
3 9 3 12
The curve will be
Please I want it by Loop or if, not manually.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

KSSV on 6 Dec 2022
data=[1 2 3 1 2 3; 7 8 9 10 11 12] ;
data = reshape(data,2,3,[]) ;
figure
hold on
for i = 1:2
plot(data(1,:,i),data(2,:,i))
end
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### More Answers (1)

Image Analyst on 6 Dec 2022
Try this:
data=[1 2 3 1 2 3; 7 8 9 10 11 12]
data = 2×6
1 2 3 1 2 3 7 8 9 10 11 12
[rows, columns] = size(data);
for col = 1 : 3
data1(col, 1) = data(1, col);
data1(col, 2) = data(2, col);
end
data1 % Show in command window.
data1 = 3×2
1 7 2 8 3 9
for col = 4 : columns
data2(col - 3, 1) = data(1, col);
data2(col - 3, 2) = data(2, col);
end
data2 % Show in command window.
data2 = 3×2
1 10 2 11 3 12
% Plot them
plot(data1(:, 1), data1(:, 2), 'b-', 'LineWidth', 2)
hold on;
plot(data2(:, 1), data2(:, 2), 'r-', 'LineWidth', 2)
Is that what you want?
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Categories

Find more on Matrix Indexing 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!

Translated by