how can i find the slope for every six rows of my data

1 Ansicht (letzte 30 Tage)
Olger Papa
Olger Papa am 8 Jan. 2018
Kommentiert: Star Strider am 9 Jan. 2018
I have data with 57.000 rows [Windspeed and time] and I want to calculate the rate of change or the slope of the windspeed for every six rows because 6 rows completes 1 hour. What fuction is possible to use for the rate of change or the slope? my final answer will be 57000/6=9500 rows or columns.

Akzeptierte Antwort

Star Strider
Star Strider am 8 Jan. 2018
One approach:
WindTime = [(0:(1/6):5-(1/6))' rand(30,1)]; % Time (Col#1), Velocity (Col#2)
WindReshape = reshape(WindTime(:,2), 6, []); % Reshape Velocity Data Only
B = [WindTime(1:6,1) ones(6,1)]\WindReshape; % Estimate Slope & Intercept
SlopeVector = B(1,:); % Save Slopes
The code reshapes your velocity data only into a 6-row, ‘N’-column matrix. It then calculates the slope and intercept (for uniformity using the first hour only for the time vector, rather than each successive hour), and then calculates the slope and intercept in matrix ‘B’. As I coded it, the slope is the first row, so extracting that gives the slopes for each hour segment. (It assumes that there are no missing or non-finite data, and does not check for those possibilities.)
If you copy your data array to ‘WindTime’, you can likely use my code without further changes.
  2 Kommentare
Olger Papa
Olger Papa am 9 Jan. 2018
Bearbeitet: Olger Papa am 9 Jan. 2018
I don't understand why rand(30,1), i think the final answer of the slope will be 9500 rows or columns because 57000/6=9500. Thank sou for your effort. I want something like that
but for every six rows
Star Strider
Star Strider am 9 Jan. 2018
As always, my pleasure.
The rand call was to create a matrix to test my code. (If possible, I always test my code before posting it.)
Note that in my ‘WindTime’ matrix, I have time in the first column and wind velocity in the second column. You will need to change the column references in my code to work with the Excel spreadsheet you read into your workspace.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

John Harris
John Harris am 8 Jan. 2018
Your formula will depend on what kind of answer you want, but I think simple math operators will do most of the work for you.
Rate of change is (windspeed2-windspeed1)/(time2-time1) ... but if you apply this to every 6th entry, you're throwing away a lot of data. What if the wind is still at the top 'o the hour, but 10 knots in opposite directions every half hour?
Perhaps you want to calculate the rate for each measurement, then take an average for each 1-hour period?
  1 Kommentar
Olger Papa
Olger Papa am 9 Jan. 2018
I thing you're right my question it was not clearly enough. I want the final answer to be slope=57000/6=9500 rows or columns.
Something like that but for for every six rows.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by