Plotting the 4th value from a data

I have a data set which i want to plot such that items 1,4,7,... are in one graph, item 2,5,8,... are in another and item 3,6,9,... are in the third. i have used the following code for plotting all these in one graph.
for i=1:n
subplot(1,n,i)
plot([0;f(:,i)],(0:h:h*n)])
end
can this be modified to get the desired graph?

Answers (1)

Hi Abdul
I certainly think so. I've define a data vector that's sinus of numbers from -10 to 10 in 111 steps - but use your own data in stead.
% Set n to be your desired increment (in this case 3 as in 4-1)
x = linspace(-10,10,111);
data = sin(x);
n = 3;
figure;
for ii = 1:n
subplot(1,n,ii)
plot(data(ii:n:end))
end

4 Comments

(Copying my answer to here since it's similar to Johannes' who posted seconds before me)
Here's a general approach you can adapt to your data.
"x" in this demo is a vector.
interval = 3;
clf()
for i = 1:interval
subplot(1,interval,i)
idx = i:3:numel(x);
plot(x(idx))
end
Note that you don't need a loop.
idx = 1:3:numel(x);
subplot(1,3,1)
plot(x(idx))
idx = 2:3:numel(x);
subplot(1,3,2)
plot(x(idx))
idx = 3:3:numel(x);
subplot(1,3,3)
plot(x(idx))
thanks for the help Johannes, just need a little more clarification or help,
there are two data sets on y axis [1; 2; 3] and on x axis [1; 2; 3; 4; 5; 6; 7; 8; 9] which using the code above will be reduced to 3 value i.e. [1; 4; 7].
can this be plotted?
Sorry for the incomplete question previously
So what you desire is to plot [1;4;7] with [1;2;3] on the y-axis in the first plot, [2;5;8] with [1;2;3] on the y-axis in the 2nd plot etc.?
If that's the case, just modify the code to
% Set n to be your desired increment (in this case 3 as in 4-1)
x = linspace(-10,10,111);
data = sin(x);
n = 3;
y = 1:n:length(x);
figure;
for ii = 1:n
subplot(1,n,ii)
plot(data(ii:n:end),y)
end

This question is closed.

Asked:

on 13 Aug 2020

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!