Plot max, min, mean of a value in a matrix
Afficher commentaires plus anciens
I have a .txt file with all the temperature of a city in different years. I need to plot maximum, minimum and medium of one month from input, per each year. Example:
input month = 8
month 8 year 1996 --> max, min, mean
month 8 year 1997 --> max, min, mean
month 8 year 1998 --> max, min, mean
(all in one graph)
I've tried this:
clear all
%load file in a matrix
mt=load('LONDON.txt');
%I save only positive value because sometimes the file doesn't have value in a row
pos = mt(mt(:,4) > 0,:);
%input from keyboard of the month that I want to plot
month= input('\n enter a month\n');
%new matrix with all the positive value of the chosen month
fin = pos(pos(:,1) == month,:);
%matrix value in a table
T = array2table(fin, 'v',{'month','day','year','temperature'});
%value of each year
res95 = T(T.month==1995,:);
res96 = T(T.month==1996,:);
res97 = T(T.month==1997,:);
res98 = T(T.month==1998,:);
res99 = T(T.month==1999,:);
res00 = T(T.month==2000,:);
res01 = T(T.month==2001,:);
res02 = T(T.month==2002,:);
res03 = T(T.month==2003,:);
res04 = T(T.month==2004,:);
res05 = T(T.month==2005,:);
res06 = T(T.month==2006,:);
res07 = T(T.month==2007,:);
res08 = T(T.month==2008,:);
res09 = T(T.month==2009,:);
res10 = T(T.month==2010,:);
res11 = T(T.month==2011,:);
res12 = T(T.month==2012,:);
res13 = T(T.month==2013,:);
res14 = T(T.month==2014,:);
now I have different tables only with the month chosen. How can I plot theme all in one graph ? Thank you.
3 commentaires
Birdman
le 24 Oct 2017
Can you share the txt file?
giasco
le 24 Oct 2017
Stephen23
le 24 Oct 2017
res95 = T(T.month==1995,:);
res96 = T(T.month==1996,:);
res97 = T(T.month==1997,:);
res98 = T(T.month==1998,:);
...
splitting data up into numbered variables is the start of writing complex, slow, buggy code. Data should be kept together as much as possible. In this case, calculating those values directly from the original array will be much simpler, e.g. using accumarray. A table could also be useful, but in the code shown serves no real purpose.
Read this to know why avoiding numbered variables is a good idea:
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!