Plot magnitude on y-axis and time on x-axis read from an excel file
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have the data as follows :
Stage Magnitude Date Time
1 -1 06/10/2012 17:56:50
1 -3 06/10/2012 17:59:33
2 -2 06/11/2012 8:52:45
2 -5 06/11/2012 8:52:46
3 -3 06/12/2012 9:11:37
3 -4 06/12/2012 9:55:56
3 -1 06/12/2013 9:57:46
4 -5 06/12/2013 10:47:49
4 -2 06/12/2013 10:48:08
4 -4 06/12/2013 10:50:35
5 -3 06/12/2013 7:47:43
5 -1 06/12/2013 8:15:30
5 -2 06/12/2013 8:16:04
I want to plot the magnitude column on y-axis and date & time on x-axis. And I want to create such plots for each Stage (as per above data I should get 5 different plots)
Can I any one tell me the format of the code?
P.S : As you can see the date and time are in serial order, I mean after 11th comes 12th june(date)and after 17:59:33 after 10th june, 8:52:45 is on 11th june
1 Commento
Risposte (3)
Ashish Gudla
il 8 Ago 2014
If you can import the excel file as column vectors, you can just loop through unique stage values and plot the respective Magnitude and Date/Time Values.
You may need to set the "XTick" and "XTickLabel" properties to make the plot look better.
Assuming you need to plot in 5 different figures (you can modify it to plot on different axes in same figure or whatever your requirement is) you could do something like this.
s = unique(Stage);
for i = s'
XData = Time(Stage == i);
YData = Magnitude(Stage == i);
DData = Date(Stage == i);
figure;
plot(XData , YData);
set(gca , 'XTick', XData,'XTickLabel', [datestr(DData) datestr(XData,'HH:MM:SS')]);
end
4 Commenti
Nir Rattner
il 8 Ago 2014
You can use the Import Data tool in the Home tab to import your data into MATLAB. At that point you can use the "datenum" function to combine the dates and times and then use the "datetick" function to properly display the dates and times on your plots.
for i = Stage(1):Stage(end)
figure;
stageIndex = Stage == i;
DateTime = datenum(Date(stageIndex)) + datenum(Time(stageIndex)) - datenum('00:00');
plot(DateTime, Magnitude(stageIndex), '-o');
datetick('x', 0);
end
Michael Haderlein
il 12 Ago 2014
Please try this:
[num,txt]=xlsread('test.xlsx');
figure
dates=datestr(datenum(txt(2:end,end-1),'mm.dd.yyyy')+num(:,end),'dd.mm.yyyy HH:MM:SS');
for cnt=1:max(num(:,1))
subplot(max(num(:,1)),1,cnt)
plot(num(num(:,1)==cnt,2))
set(gca,'xtick',1:sum(num(:,1)==cnt),'xticklabel',dates(num(:,1)==cnt,:))
end
On my computer, Excel changed the date format from mm/dd/yyyy automatically to mm.dd.yyyy. So maybe you need to change this in the dates line.
8 Commenti
Michael Haderlein
il 14 Ago 2014
I don't understand you code in every detail. If you use my code, change both "dd.mm.yyyy" to "mm/dd/yyyy", what will be the error? If you want, you can also change "subplot(max(num(:,1)),1,cnt)" to simply "figure".
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!