I'd like to construct a graph like the following which is done with excel:
I've entered my data into matlab using the following lines:
year = [1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
]
fix_No = [-9.449167466 -11.19432509 -8.500517848 -5.644813211 -2.608063866 2.614370892 6.461752833 7.035549084 8.542521755 12.11070577 6.476900841 8.029225388 4.315820526 4.165349512 5.34593031 7.510812752 -2.629044124 -5.713139529 -8.626773532 -11.83226415 . -8.821345246 -6.396197293 -5.187823611 -1.79008821 3.34099288 5.545228048 7.013763711 6.580524638 4.256524275
]
fix_No_and_mean = [11.1610424 5.437315474 5.833032482 4.591658232 1.578021362 -1.572756298 -1.03351595 -2.250991302 -3.222969261 -5.734621837 . 12.96685642 10.95095066 10.2207684 5.654017602 1.753259697 -2.596143576 -7.155087995 -9.687001589 -8.700979283 -4.290434459 . 2.299711172 1.640802028 1.714407543 0.8360893 -0.425484303 -1.160053823 -0.858530711 0.123787867 0.782208621
]
In 1985 and 1996 the lines should be interrupted as in the excel graph. But how can I do this using Matlab? I've put a "." (point) where the interruptions should be but matlab doesn't accept points.
The lines for the construction of the graph look like this:
plot(year,fix_No, 'color', 'k', 'LineWidth',2, 'LineSmoothing','on')
line(year,fix_No_and_mean, 'color', 'r', 'LineWidth',2, 'LineSmoothing','on')
xlabel('year')
legend('fixed number', 'fixed number')
You Should put "NaN" instead of '.' ,i.e. in the places on the vectors fix_No_and_mean and fix_No that correspond to 1985 and 1996, put NaN.
This will plot different lines as in the figure you attached from excel.
Related
I need to extract the date from this text:
Mellisoni 2014 Malbec (Columbia Valley (WA))
Okapi 2013 Estate Cabernet Sauvignon (Napa Valley)
Podere dal Nespoli 2015 Prugneto Sangiovese (Romagna)
Simonnet-Febvre 2015 Chablis
Lagler 2012 1000 Eimerberg Smaragd Neuburger (Wachau)
I use this code:
vino<-mutate(vino, year1=sub("^.*([0-9]{4}).*", "\\1", vino$title))
It works, but I have the last value extract on 1000 instead of 2012, how can I fix it if have another numbers?
I am reading a csv file in Matlab using textread function and storing the values in the cells of string and float types.
[string1, string2, values] = textread('/path/xyz.csv', '%s %s %f', 'headerlines', 1);
Data has three columns. Two of them I believe are of string type and one is float.
Sample Data
#timestamp host value
March 5th 2019, 13:41:54.879 tscompute1 0.399
March 5th 2019, 13:41:54.879 tscompute1 0.599
March 5th 2019, 13:41:54.879 tscompute1 0
March 5th 2019, 13:41:54.879 tscompute1 0.2
March 5th 2019, 13:41:54.879 tscompute1 0
March 5th 2019, 13:41:54.879 tscompute1 0
March 5th 2019, 13:41:54.879 tscompute1 0
March 5th 2019, 13:41:54.879 tscompute1 0
March 5th 2019, 13:41:54.879 tscompute1 0
March 5th 2019, 13:41:54.879 tscompute1 100
March 5th 2019, 13:41:54.879 tscompute1 0.4
There is not execution error. But the read values are not as expected. Please find the sample output below.
Values stored in string1 looks like as follows
'"March'
','
'"March'
','
'"March'
','
'"March'
','
Values stored in string2 looks like as follows
'5th'
'13:41:54.879",tscompute1,0.399'
'5th'
'13:41:54.879",tscompute1,0.599'
'5th'
'13:41:54.879",tscompute1,0'
'5th'
'13:41:54.879",tscompute1,0.2'
Values stored in values looks like as follows
2019
0
2019
0
2019
0
2019
0
Your text seems to have inconsistent delimiters, the date is separated from the time by a comma, while the time, the name "tscompute1" and the number are separated by white-spaces.
The simplest is to read every line as six elements each separated by white-spaces with five of them being strings and the sixth being a number.
[s1, s2, s3, s4, s5, values] = textread('/path/xyz.csv', '%s %s %s %s %s %f', 'headerlines', 1);
That allows you to get the date (concatenate strings in s1-s3, remove the trailing comma), the time (s4), the name (s5) and the value.
I have a matrix that has 3months of data or so..Its a 952x1 matrix with the elements in the following format(3 hourly )
Aug-05-2015 03:00:00
Aug-05-2015 06:00:00
Aug-05-2015 09:00:00
Aug-05-2015 12:00:00
Aug-05-2015 15:00:00
Aug-05-2015 18:00:00
Aug-05-2015 21:00:00
Aug-06-2015 00:00:00
Aug-06-2015 03:00:00
Aug-06-2015 06:00:00
I would want to choose say only day timings/ only night or say for august month alone. How do i do that.
Further to my question, if I have a group of .wav files and Im trying to pick only month wise or do daily psd averages etc or chose files belonging to a month how to go about? The following are first 10 .wav files in a .txt file that are read into matlab code-
AMAR168.1.20150823T200235Z.wav
AMAR168.1.20150823T201040Z.wav
AMAR168.1.20150823T201845Z.wav
AMAR168.1.20150823T202650Z.wav
AMAR168.1.20150823T203455Z.wav
AMAR168.1.20150823T204300Z.wav
AMAR168.1.20150823T205105Z.wav
AMAR168.1.20150823T205910Z.wav
AMAR168.1.20150823T210715Z.wav
yyyymmddTHHMMSSZ.wav is part of the format to get sense of some parameters.
Thanks.
Are these datetimes? If so, you can use logical indexing here if you make use of some of the datetime functions. To get the times in August:
t = datetime(2015, 8, 1, 3, 0, 0) + hours(3:3:3000)';
t(month(t) == 8) % Times in August
To get the times that are during the day or night:
t(hour(t) < 12) % Day times
t(hour(t) >= 12) % Night times
I have the following time series:
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1948 24.786 24.767 25.117 25.514 26.565 27.374 27.778 28.022 27.827 27.308 26.545 25.620
1949 25.191 24.962 25.038 25.591 26.325 27.044 27.719 28.059 28.077 27.541 26.501 25.568
1950 24.713 24.461 24.682 25.122 26.157 26.965 27.688 28.072 28.089 27.429 26.318 25.194
1951 24.423 24.114 24.335 25.153 26.399 27.474 28.143 28.547 28.441 27.854 26.904 25.842
1952 25.025 24.812 25.317 25.734 26.660 27.615 28.069 28.468 28.384 27.738 26.640 25.402
1953 24.619 24.614 25.048 25.917 26.870 27.485 28.021 28.363 28.311 27.687 26.768 25.829
1954 25.176 24.804 25.089 25.768 26.579 27.222 27.684 28.053 27.971 27.164 26.141 25.162
1955 24.553 24.340 24.679 25.266 26.182 26.959 27.649 28.108 28.053 27.453 26.594 25.483
1956 24.492 24.361 24.791 25.446 26.295 26.867 27.505 27.946 27.889 27.420 26.347 25.504
1957 24.928 24.811 25.110 25.690 26.677 27.566 28.221 28.486 28.459 27.793 26.889 25.794
1958 24.982 24.616 25.134 25.940 26.842 27.887 28.421 28.758 28.712 28.085 27.185 26.233
1959 25.432 25.376 25.469 25.987 26.726 27.424 28.042 28.242 28.349 27.988 26.962 26.049
1960 25.364 25.060 25.195 25.877 26.907 27.645 28.187 28.427 28.344 28.002 27.124 25.859
1961 25.194 25.116 25.415 25.907 26.755 27.363 27.960 28.269 28.224 27.672 26.792 25.849
1962 25.335 25.174 25.257 25.696 26.708 27.386 28.144 28.467 28.398 27.828 26.593 25.624
1963 25.103 24.899 25.371 25.914 26.646 27.481 27.953 28.341 28.277 27.652 26.733 25.661
1964 25.023 24.864 25.188 25.678 26.622 27.434 27.753 27.950 27.859 27.217 26.348 25.285
1965 24.478 24.373 24.636 25.399 26.180 26.973 27.499 27.912 27.954 27.550 26.709 25.768
1966 24.885 24.625 24.797 25.494 26.307 27.183 27.877 28.186 28.225 27.728 26.615 25.466
1967 24.794 24.639 24.872 25.375 26.345 27.023 27.564 27.914 27.973 27.529 26.550 25.478
1968 24.521 24.180 24.466 25.344 26.259 27.241 27.929 28.349 28.283 27.681 26.692 25.643
1969 24.838 24.668 25.022 26.111 27.064 27.970 28.415 28.547 28.431 27.852 26.705 25.604
1970 24.849 24.565 24.964 25.809 26.502 27.206 27.793 28.065 28.101 27.570 26.367 25.412
1971 24.756 24.505 24.660 25.258 26.161 26.984 27.564 27.832 27.747 27.238 26.304 25.473
1972 24.903 24.638 25.025 25.624 26.355 27.086 27.629 27.938 28.112 27.757 26.969 26.070
1973 25.217 24.837 25.237 25.591 26.594 27.422 27.919 28.030 27.989 27.440 26.454 25.131
1974 24.783 24.371 24.839 25.495 26.199 27.103 27.608 27.938 27.907 27.200 26.276 25.229
1975 24.622 24.564 24.867 25.532 26.407 27.202 27.545 27.947 27.777 27.236 26.326 25.045
1976 24.058 23.905 24.467 25.101 25.954 26.744 27.458 27.854 27.899 27.539 26.537 25.631
1977 24.768 24.636 25.078 25.422 26.202 27.195 27.869 28.085 28.096 27.613 26.797 25.758
1978 24.876 24.496 24.901 25.673 26.661 27.311 27.762 28.034 28.025 27.584 26.828 25.851
1979 24.920 24.658 24.853 25.461 26.285 27.295 27.820 28.137 28.090 27.640 26.608 25.577
1980 24.917 24.588 25.038 25.697 26.828 27.554 28.094 28.295 28.269 27.653 26.622 25.470
My time series has an anual cycle and I want to see how it changes in another temporal scales (e.g 5 or 6 years) but I don't really know how to do it. I should make it using digital filters.
Assuming you have the data in a matrix M.
%Averaging period
k = 12*5;
%How often you want to have a lebel, you're going to need to play with this
timeUnits = 10*12;
startYear = 1948;
endYear = 1980;
startMonNum = 1;
endMonNum = 12;
%Get all the months and years
[year, mon] = meshgrid(startYear:endYear, 1:12);
%Convert them to a single column and put them in a nice format
dates = reshape(arrayfun(#(x, y) datestr(datenum(x,y,1),'mmm yyyy'), year,mon,'uni', 0), [], 1);
dates = dates(startMonNum:end-endMonNum+12);
%Change your data from a square matrix to a column
M = reshape((1:length(dates)), [], 12);
%Smooth
MPrime = smooth(reshape(M', [], 1), k);
plot(1:length(MPrime), MPrime)
%This is where you'll need to play around some
%Put strings at the bottom of the axis
set(gca, 'Xtick',1:timeUnits*floor(length(MPrime)/timeUnits))
set('XTickLabel',dates(1:timeUnits:end))
How do I get the year (4 digits) when given a source code, I can only detect the day (29), but could not detect the year(1997). There is something wrong in my regexp checking.
age = regexp(CharData,'(\d{1,4})','match','once')
For example,
Registered On
March 29, 1997
Desired output: 1997
Error output: 29
for i = 1:2
data2=fopen(strcat('DATA\PRE-PROCESS_DATA\F22_TR\f22_TR_pdata_',int2str(i),''),'r')
CharData = fread(data2, '*char'); %read text file and store data in CharData
fclose(data2);
age = regexp(CharData,'(\d{4})','match','once')
end
file : f22_TR_pdata_1 --> Registered On
June 24, 1997
file : f22_TR_pdata_2 --> Registered On
March 29, 1997
Age: 1997
To only grab four digits
age = regexp(CharData,'(\d{4})','match','once')
Doing d{1,4} means look for numbers with a length between 1 and 4. Meaning, 1, 29, 123, 4444 would all match because their length is between 1 and 4
d{4} says, get me the number with exact length of 4. Meaning, 1997, 2001, 1800 would all match.