How can I find the average slope of many lines?
3 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Image Analyst
2015-2-27
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!