How I can substract vectors with different length?

2 ビュー (過去 30 日間)
gjashta
gjashta 2019 年 5 月 5 日
コメント済み: dpb 2019 年 5 月 5 日
If d is a vector containg the data for each day of march for 13 years. So, d is a vector with 403 values.
Then mu and sd are the mean and standard deviation of march for each year. mu and sd are vectors with 13 values.
I need to calculate first d-mu, and then d-mu/sd. How to do it in matlab?
  3 件のコメント
gjashta
gjashta 2019 年 5 月 5 日
編集済み: gjashta 2019 年 5 月 5 日
d is the daily demand and mu is the mean for each month.
Yes,
Adam Danz
Adam Danz 2019 年 5 月 5 日
ah.... right. I see now. I thought maybe you were computing delta-mu.

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

採用された回答

dpb
dpb 2019 年 5 月 5 日
編集済み: dpb 2019 年 5 月 5 日
I presume you mean to standardize the monthly data by year...presuming you have a date variable along with the observation, then findgroups and splitapply will do the job; otherwise the "dead-ahead" solution is to just repelem the values of the mean, sd array...
z=(d-repelem(mu,31))./repelem(sd,31);
where I've used mu, sd for mean, std dev instead of ill-chosen x, y
ADDENDUM
Would have been easier to have been told what things were from the git-go instead of having to download the data...but
d.StdDemand=(d.Demand-repelem(mu.Demand,31))./repelem(sd.Demand,31);
dereferences all the timetables.
In general, since you'll undoubtedly be wanting to do this for other months, replace the hardcoded 31 with a variable for the proper number of days in month (also remembering to account for leap years for February).
  7 件のコメント
gjashta
gjashta 2019 年 5 月 5 日
Thank you! Yeah, I plan to do this for other months, as well.
I have attached the daily demand of 13 years and the monthly mean and standard deviation.
Can you help me with a simple code that can standardize the monthly data by year without repeating the same code for each month (as you said I have to take into account the leap years for February).
dpb
dpb 2019 年 5 月 5 日
And, I just showed code that works on that data here in the amended Answer.
As for leap years and days therein, eomday() is leapyear aware so using it instead of hardcoded days would be one way.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by