Calculate slope at specific time over many days using polyfit and for loop

3 ビュー (過去 30 日間)
Benjamin Downing
Benjamin Downing 2019 年 9 月 14 日
コメント済み: Star Strider 2019 年 9 月 14 日
I have a data set that show daily fluctuation in groundwater. I need to find the slope of the hydrograph every day between the hours of 4 and 12. I have tested this loop with other operators and they are working on the correct intervals. the hours 12 to 4 correspond to the first 17 rows of every 96 rows.
How do I correctly use polyfit to calculate slope during the assigned intervals?
The error I am recieving is as follows:
Unable to perform assignment because the indices on the left side are not compatible with the size of
the right side.
Error in ETg_toy (line 105)
tR(h)=polyfit(subset_day,subset_depth,1)
Below is the code I am trying to use:
load('GroundwaterDataA');
A = GroundwaterDataA;
depth=flip(A(:,2))
day=flip(A(:,1))
for h=1:200 %day day 200 = day 199
start2=(h*96)-15;
endp2=h*96;
subset_depth=depth(start2:endp2)
subset_day=day(start2:endp2)
tR(h)=polyfit(subset_day,subset_depth,1)
pause
end

採用された回答

Star Strider
Star Strider 2019 年 9 月 14 日
You appear to be calculating them correctly, just not storing them correctly. For a linear fit, polyfit will produce a (1x2) vector of the coefficients.
Try this:
tR(h,:)=polyfit(subset_day,subset_depth,1)
Note the added dimension.
  2 件のコメント
Benjamin Downing
Benjamin Downing 2019 年 9 月 14 日
That solved the issue. Thank you for your help!
Star Strider
Star Strider 2019 年 9 月 14 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by