MATLAB Answers

How I can substract vectors with different length?

2 views (last 30 days)
gjashta on 5 May 2019
Commented: dpb on 5 May 2019
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?


gjashta on 5 May 2019
d is the daily demand and mu is the mean for each month.
Adam Danz
Adam Danz on 5 May 2019
ah.... right. I see now. I thought maybe you were computing delta-mu.

Sign in to comment.

Accepted Answer

dpb on 5 May 2019
Edited: dpb on 5 May 2019
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...
where I've used mu, sd for mean, std dev instead of ill-chosen x, y
Would have been easier to have been told what things were from the git-go instead of having to download the data...but
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).


Show 4 older comments
dpb on 5 May 2019
As I said, "t" was a placeholder for your (unidentified) table name; also d, mu, sd are presumed variable names inside the table.
You have to apply the logic to the data structure(s)/variable names you're using...see amended answer.
gjashta on 5 May 2019
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 on 5 May 2019
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.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!