pac
pac

Reputation: 291

selecting certain points to be plotted

I am plotting number of correct and functioning sensors at each 100 runs.

I will get the following plot: result wrt runs

The 100 readings taken for each of the runs is somewhat confusing. How can I make matlab plot

  1. At every 5 values (5,15,20....)

  2. The average of 5 runs so that number of plots will be 100/5.

can you help in these two cases thanks

if round=10 in the original case will have 10 bars,

With the formula given by @Richante data_to_plot = data(1:5:end); will have 2 bars. Great but when I plot will get values at Round 1 and 2. How to display that these are for rounds 1 and 5?

Upvotes: 0

Views: 3502

Answers (1)

Richante
Richante

Reputation: 4388

You can plot every 5th item by slicing the array:

data = %1-by-100 array
data_to_plot = data(1:5:end);

To plot the average of 5 runs, you could do a for-loop:

data_to_plot = zeros(1, 20);
for i=1:20
  data_to_plot = mean(data((i-1)*5:i*5));
end

Or a neat way is to reshape the array into a 5-by-20 matrix and take the mean in the first dimension:

data_to_plot = mean(reshape(data, 5, 20));

Upvotes: 2

Related Questions