How I can substract vectors with different length?

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 Commenti

Is d-mu the change in monthly means?
gjashta
gjashta il 5 Mag 2019
Modificato: gjashta il 5 Mag 2019
d is the daily demand and mu is the mean for each month.
Yes,
ah.... right. I see now. I thought maybe you were computing delta-mu.

Accedi per commentare.

 Risposta accettata

dpb
dpb il 5 Mag 2019
Modificato: dpb il 5 Mag 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...
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 Commenti

gjashta
gjashta il 5 Mag 2019
Modificato: gjashta il 5 Mag 2019
Yes, I want to standardize the monthly data by year.
I got this error:
z=(d-repelem(mu,31))./repelem(sd,31);
Error using tabular/repelem (line 14)
REPELEM requires exactly three input arguments when the first input is a table.
I uploaded also the data of march for 13 years.
Dereference the table data to arrays--
z=(d-repelem(t.mu,31))./repelem(t.sd,31);
where 't' is placeholder for your table variable name...if d is also in the table and not a vector, then same goes for it as well...
t.z=(t.d-repelem(t.mu,31))./repelem(t.sd,31);
would add the standardized variable 'z' to the existing table, t...
Well, clarify what you have to start with--you started the Q? with a vector of length 310 and another of length 10. With those two inputs, the original code would work just fine.
Then you said you had a table -- dereferencing a table would create vectors (excepting, of course, a table has to have the same number or rows for all variables so that really couldn't have been -- I made a too hasty reply there).
Now you've attached a .mat file that has 4748x2 elements which has seemingly no relation to the original Q? at all...
What happend to the 310 and 10 length vectors? Get them back and go back to the original answer and joy should ensue...
Ok,you are right I confused you.
In the mat-files above we have d, mu,sd vectors with different lengths. When I run:
t.z=(t.d-repelem(t.mu,31))./repelem(t.sd,31);
or
z=(d-repelem(t.mu,31))./repelem(t.sd,31);
I got this error
z=(d-repelem(t.mu,31))./repelem(t.sd,31);
Dot indexing is not supported for variables of this type.
also
t.z=(t.d-repelem(t.mu,31))./repelem(t.sd,31);
Dot indexing is not supported for variables of this type.
dpb
dpb il 5 Mag 2019
Modificato: dpb il 5 Mag 2019
t.z=(t.d-repelem(t.mu,31))./repelem(t.sd,31
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.
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).
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.

Accedi per commentare.

Più risposte (0)

Tag

Richiesto:

il 5 Mag 2019

Commentato:

dpb
il 5 Mag 2019

Community Treasure Hunt

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

Start Hunting!

Translated by