How can I find the average slope of many lines?

4 vues (au cours des 30 derniers jours)
Daniel Lynch
Daniel Lynch le 27 Fév 2015
Commenté : Daniel Lynch le 27 Fév 2015
I have a large amount of raw data which I need to analyse.
The data describes the wind direction, speed and the height at which the measurement was taken.
Basically, if the wind direction is between 315 and 360 degrees. I would like to graph the natural log of the speed against the natural log of the height. The slope of this line is the shear exponent.
Each row of the excel spreadsheet contains the relevant information necessary to generate a graph and calculate the slope. I would to find the mean slope of all rows.
The code below is what I've written so far. However, I think
line = polyfit(x,y,1);
m = line(1);
Is only finding the slope of the first row.
tic;
kane = 'Kane_Data_Splice.xlsx';
Height = [19 44 69 90 148];
Speed = [xlsread(kane,'BA:BA') xlsread(kane,'AS:AS') xlsread(kane,'AK:AK') xlsread(kane,'AC:AC') xlsread(kane,'U:U')];
Direction = xlsread(kane,'T:T');
n = numel(Direction);
for i = 1:n
if (315 < Direction(i)) && (Direction(i) < 360)
p = repmat(log(Height),n,1);
q = log(Speed);
x = p(i,:);
y = q(i,:);
line = polyfit(x,y,1);
m = line(1);
end
end
m
ExecutionTime = toc
Thanks for your help!

Réponse acceptée

Image Analyst
Image Analyst le 27 Fév 2015
One way to do it is to use a counter and then take the average after the loop.
counter = 1;
for i = 1:n
if (315 < Direction(i)) && (Direction(i) < 360)
p = repmat(log(Height),n,1);
q = log(Speed);
x = p(i,:);
y = q(i,:);
line = polyfit(x,y,1);
m(counter) = line(1);
counter = counter + 1;
end
end
meanSlope = mean(m);
  1 commentaire
Daniel Lynch
Daniel Lynch le 27 Fév 2015
Your solution works perfectly. Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Spline Postprocessing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by