my data set looks like this...
Product, DateTime, Value
P1, 2023-02-01 12:00, 1
P1, 2023-02-01 13:00, 1.5
P1, 2023-02-01 14:00, 1.8
P1, 2023-02-01 15:00, 1.3
P1, 2023-02-01 16:00, 2
P2, 2023-02-01 13:00, 4
P2, 2023-02-01 14:00, 4.5
P2, 2023-02-01 15:00, 6
P2, 2023-02-01 16:00, 6.3
P2, 2023-02-01 17:00, 3
I want to create a line chart that shows P1, P2, P3 on the same chart but can't get it done properly. The chart seems a bit weird. I tested the same thing using SSRS and Excel, no problem to get it automatically populated. Some how Crystal Report a bit different behaviour.
Y axis = value
X axis = time
Anybody having success doing it ?
Related
How do I convert monthly data into quarterly data?
For example:
my 1 table looks like this:
TB3m
0.08
0.07
0.06
0.12
0.13
0.14
my second table is table of dates:
dates
1975/01/31
1975/02/28
1975/03/31
1975/04/30
1975/05/31
1975/06/30
I want to convert table 1 such that it takes the average of 3 months to give me quarterly data.
It should ideally look like:
TB3M_quarterly
0.07
0.13
so that it can match my other quarterly dates table which looks like:
dates_quarterly
1975/03/31
1975/06/30
Over all my data is from 1975 January to 2021 june which would give me around 186 quarterly data. Please suggest what I can use. It is thefirst time I am using matlab
In case you can't understand a command, search for it in MATLAB documentation. One quick way to do so in Windows is to click on the function you don't understand and then press F1. For example, if you can't understand what calmonths is doing, then click on calminths and press F1.
TBm = [0.08; 0.07; 0.06; 0.12; 0.13; 0.14]; %values
% months
t1 = datetime(1975, 01, 31); %1st month
% datetime is a datatype to represent time
t2 = datetime(1975, 06, 30); %change this as your last month
dates = t1:calmonths(1):t2;
dates = dates'; %row vector to column vector
TBm_reshaped = reshape(TBm, 3, []);
TB3m_quarterly = mean(TBm_reshaped);
dates_quarterly = dates(3:3:end);
TB3m_quarterly = TB3m_quarterly';
T = table(dates_quarterly, TB3m_quarterly)
I suggest you organize your data in a timetable, and then use the function retime()
% Replicating your data
dates = datetime(1975,1,31) : calmonths(1) : datetime(1975,6,30);
T = timetable([8 7 6 12 13 14]'./100, 'RowTimes', dates);
% Using retime to get quarterly values:
T_quarterly = retime(T, 'quarterly', 'mean')
Here you aggregate by taking the mean of the monthly data. For other aggregation methods, look at the documentation for retime()
% S
a1 = [2015/07/23 2015/11/25 2016/01/20];
b1 = [2011/06/22 2014/10/14 2015/03/01];
c1 = [2012/04/16 2013/06/23 2015/04/08];
d1 = [2013/09/15 2014/01/19 2016/09/13];
e1 = [2015/04/01 2016/04/04 2018/08/04];
% H
a2 = [2012/07/23 2015/06/25 2016/05/20];
b2 = [2009/06/22 2014/09/14 2015/11/01];
c2 = [2006/04/16 2013/12/23 2015/06/08];
d2 = [2008/09/15 2014/05/19 2016/02/13];
e2 = [2011/04/01 2016/05/04 2018/03/04];
% HS
a3 = [2009/07/23 2010/06/25 2018/02/20];
b3 = [2011/06/22 2014/07/14 2016/09/01];
c3 = [2013/04/16 2016/09/23 2019/05/08];
d3 = [2013/09/15 2018/05/19 2019/06/13];
e3 = [2014/04/01 2019/01/04 2019/12/04];
% T
t = [1 2 3 4 5];
dates = [a1 a2 a3; b1 b2 b3; c1 c2 c3; d1 d2 d3; e1 e2 e3];
% Plotted
figure
barh(t, dates, 'hist')
title('Script')
xlabel('Time')
ylabel('Tail')
legend({'S','H','HS'})
legend('Location', 'southoutside')
legend('Orientation','horizontal')
If you plot this, you will notice that there are 9 bar graphs associated with each 't'. There should be only three as stated in the 'dates' variable per t. How do I stack 'a1,a2,a3, then b1,b2,b3 ...... and e1,e2,e3 each individually' to accomplish this feat?
My script result:
What I want the output to look like
Note: 1. The y axis contains the 5 different elements 't'
2. The x axis should contain the date elements 'dates'
3. When you plot these values, there are 9 bars. There should be three per
't'.
4. On the x axis, I would like to have the dates represented.
5. I would like to eventually be able to create a user prompted system that
allows people to enter in dates for a corresponding array, and have that
date be stacked onto the chart.
The following bit of code does a bit of what I ask for but with the bars stacked vertically not horizontally, and also takes in different user inputs.
https://www.mathworks.com/matlabcentral/fileexchange/32884-plot-groups-of-stacked-bars
You are very close to a solution. Download that file from MATLAB file exchange, open it, replace bar with barh, you got your own horizontally stacked bar plot.
Your input does not fit the expected format, the function expects a 3d matrix. A minor change to your code:
dates = [cat(3,a1,a2,a3);cat(3,b1,b2,b3); cat(3,c1,c2,c3); cat(3,d1,d2,d3); cat(3,e1,e2,e3)];
plotBarHStackGroups(dates,t)
I have a script that cumulates my data and plots it afterwards. In my case my data are temperatures and the plots show the number of hours a year in which these temperatures and every temperature below are reached.
For example:
in 7500 hours a year it is 25 degree and colder
in 6000 hours a year it is 20 degree and colder
I get the result that i need using the matlab scrpit below:
filenameTRY2035='TZ10.dat';
daten = dlmread(filenameTRY2035);
TZ10 = sort(daten(1:length(daten)));
A = length(TZ7); A = A';
% plot
figure(1)
clf(1)
hold on;
h1 = plot(TZ10,A);
Now I want the temperatures counted the other way around.
For example:
in 1000 hours a year its 25 degrees and hotter
in 3500 hours a year it is 20 degrees and hotter
Could anyone help me modify my script in the way that I get the plots I need?
Thanks a lot,
Cheyenne
So let's say you have
TZ10 =
.... 7000 7300 7500 ....
7500 -> 25° or colder
7300 -> 24° or colder
7000 -> 23° or colder
...
And there are 8766 hours in a year.
Then the reversed order would be
l = length(TZ10);
TZ10_reverse(l) = 8766 - TZ10(1)
for temp = 2:l
TZ10_reverse(l - temp + 1) = (8766 - TZ10(temp)) + (TZ10(temp) - TZ10(temp - 1));
end
Because if there are 8766 hours a year and 7500 hours equals or colder than 25° a year, then there are 8766 - 7500 strictly warmer than 25° a year and TZ10(25) - TZ10(24) days equals to 25°
I also did it in order to get it sorted!
By the way....
TZ10 = sort(daten(1:length(daten)));
is equivalent to
TZ10 = sort(daten);
The elements of daten from 1 to the max index of daten is basicly daten itself!
I am producing this graph (reduced code version) :
k = 1000
r = [100 220 470 1*k 2200 4700 10*k 22*k 47*k 100*k 220*k 470*k 1000*k ]
unModNB = [0.72 0.746 0.801 0.92 1.16 1.69 2.78 4.6 6.45 9.1 11.2 12.4 13.2]
unModWB = [1.124 1.17 1.23 1.48 1.84 2.65 4.2 7.6 11.8 15.4 18.6 20.01 21.7]
ModNBdB = 20*log10( ModNB)
ModWBdB = 20*log10( ModWB)
semilogx( r, ModNBdB, r, ModWBdB )
grid
legend(Line 1 ', 'Line 2')
How am I able to produce another graph of the delta between line 1 and line 2 across intervals of delta across the full scale?
I want to avoid simply using the reading deltas because of the 'jumpy' graph that this meathod generates.
Many many thanks for any help,
Ed.
I believe what you want to do is interpolate between the unModNB and unModWB points and calculate the differences (deltas, as you say) between those. For that you can use interp1(). Try this:
k = 1000;
r = [100 220 470 1*k 2200 4700 10*k 22*k 47*k 100*k 220*k 470*k 1000*k ];
unModNB = [0.72 0.746 0.801 0.92 1.16 1.69 2.78 4.6 6.45 9.1 11.2 12.4 13.2];
unModWB = [1.124 1.17 1.23 1.48 1.84 2.65 4.2 7.6 11.8 15.4 18.6 20.01 21.7];
ModNBdB = 20*log10( unModNB );
ModWBdB = 20*log10( unModWB );
semilogx( r, ModNBdB, r, ModWBdB )
grid
legend('Line 1', 'Line 2')
sampled_x_vals = linspace(r(1),r(end),1000);
unModNB_sampled = interp1(r, unModNB, sampled_x_vals, 'pchip');
unModWB_sampled = interp1(r, unModWB, sampled_x_vals, 'pchip');
deltas = unModWB_sampled-unModNB_sampled;
figure, semilogx(sampled_x_vals,deltas), grid;
If, by 'deltas' you mean something other than difference, please clarify.
I have the following set of data stored in file stations.dat :
Station A 305.2 321.1 420.9 383.5 311.7 197.1 160.2 113.9 60.5 60.5 64.8 154.3
Station B 281.1 304.0 353.1 231.9 84.6 20.9 11.7 11.9 31.1 75.8 133.0 235.3
Station C 312.3 342.2 366.2 335.2 200.1 74.4 45.9 27.5 24.0 53.6 87.7 177.0
Station D 402.2 524.5 554.9 529.5 347.5 176.8 120.2 35.0 12.6 13.3 14.0 61.6
Station E 261.3 262.7 282.3 232.6 103.8 33.2 16.7 33.2 111.0 149.0 184.8 227.0
By using the following commands,
Z = linkage (stations.data,'ward','euc');
figure (1), dendrogram(Z,0,'orientation', 'right')
I get the figure below:
So cluster 1 components are 4,3,1 (Stations D,C and A, respectively) and cluster 2 are 5,2(Stations E and B).
I want to put the name of Stations on plot, but if I use the command:
set (gca,'YTickLabel', stations.textdata);
The figure I get is the following:
How can I associate data to respective names and plot in dendrogram.
I have 144 stations data. I used only 5 for illustration.
Try the following:
ind = str2num(get(gca,'YTickLabel'));
set(gca, 'YTickLabel',stations.textdata(ind))
An easier way would be to specify the labels of the data points in the dendrogram call directly:
dendrogram(Z,0, 'Orientation','right', 'Labels',stations.textdata)