Plotting the average line of a graph of a column imported from an excel
Afficher commentaires plus anciens
I have an imported table from an excel file of a large column with 15808 rows, I had successfully plotted it but I'd also like to plot an average line of these whole values. I tried many average functions and checked many similar questions on the website but that didn't really help. I also calculated the average of the column with its length and its sum (the code below, while x is the clumn of the values in the workspace) but the line stays at 0..
Is there any suggested function how to plot the average of a large column with values?
len = length(x);
sum = 0;
for i = 1 : len
sum = sum + x(i);
end
Avg = sum / len;
Réponse acceptée
Plus de réponses (1)
Shae Morgan
le 13 Août 2020
Wha about this:
t1 = datetime(2020,8,12,13,11,24); %start time
t2 = datetime(2020,8,12,13,18,36); %end time
time5 = t1:seconds:t2; %create a vector of time points from the start time to the end time
v5 = randn(size(time5)); %create random y-axis data
plot(time5,v5) %plot data
hold on; %hold the current figure so the first plot doesn't erase when you do the 2nd plot
avg5 = mean(v5); %the average value of v5
x2= [time5(1) time5(end)]; %x-values for the average line
plot(x2,[avg5 avg5], 'y-', 'LineWidth',2); %plot the avg line
title('value 5 by time plot') %title the plot
legend('Raw data','Average line') %add a legend to differentiate the two data sources
ax = gca; %get current axis
x_step_size=100; %step size between labels in seconds
ax.XAxis.TickValues = t1:seconds(x_step_size):t2; %adjust the tick values to the correct spacing

1 commentaire
Shae Morgan
le 14 Août 2020
If this better answers your question, please accept
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
