Using the min and max function for form a new variable

3 visualizaciones (últimos 30 días)
Farai Mwashita
Farai Mwashita el 27 de Oct. de 2014
Comentada: Farai Mwashita el 28 de Oct. de 2014
Hello
I am calculating HDD (heating degree days) and CDD (cooling degree days)and have managed to reshape the data to get a dailyT =reshape(data:,4)24,365). Now I need to use the min and max functions to create new variables (1 x 365) of daily min and max temperature and I am stuck on this stage.
Please can you assist on how to do this.
Regards
Farai

Respuestas (3)

Adam
Adam el 27 de Oct. de 2014
Editada: Adam el 27 de Oct. de 2014
If your data is (24,365) then you can just use the normal form:
dailyMins = min( data );
dailyMaxes = max( data );
to get (1,365)-sized results.
If you wanted to be explicit you can use:
dailyMins = min( data, [], 1 );
to tell min to calculate along dimension 1, thus returning a result of size equal to dimension 2, but since this is the default behaviour that is un-necessary. However, if your data happened to be (365,24) then you could use this method with a '2' as the final argument to achieve the same result.

Farai Mwashita
Farai Mwashita el 28 de Oct. de 2014
Hello Adam
Thank you for your help.

Farai Mwashita
Farai Mwashita el 28 de Oct. de 2014
hello
I have managed to calculate the average daily temperatures (1 x 365) and now I need to reshape this into monthly averages. I have been told the loop function can used, can you please assist on how to do so?
Regards
Farai
  2 comentarios
Adam
Adam el 28 de Oct. de 2014
That is more than a reshape option, you would need to break down your 365 days into months, average each of these and then end up with a length 12 result.
e.g.
m = [31 28 31 30 31 30 31 31 30 31 30 31];
to give you the lengths of each month. Then a generic version of the following example:
monthlyAverage(1) = mean( dailyMins( 1:m(1) ) )
monthlyAverage(2) = mean( dailyMins( (m(1) + 1):( m(1) + m(2) ) ) );
etc, etc.
There are neater ways to do that of course in a generalised way than just writing out 12 hard-coded lines, but I'll leave that as an exercise for you.
You may find
cumsum( m );
to be very useful in simplifying the indexing into m.
Farai Mwashita
Farai Mwashita el 28 de Oct. de 2014
Hello
When i try to calculate for the second month, I get an error message saying unbalanced or enexpected parentesis or bracket. I can't seem to get past this stage.
Regards
Farai

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by