-1

I have an acquisition by a ph-meter, divided into 3 days. I have extracted the time in hh:mm:ss format for each day. It means that first day is from 12:32 to 14:39, second from 14:12 to 16:17 etc. Same for the temperature (from 23 to 24°, 2 day from 22 to 24 etc).

Now I have to plot the data (ph wrt T and Time), but if I concatenate the 3 time and T vectors, or create a single column vector for each time and temperature, MATLAB automatically sorts in increasing values the values of the x-axis of the plot. I need to preserve the original values along the axes (it means that values have to be 14:32 14:33 14:34 12:24 12:25 and so on, same for temperature) because i have to preserve the continuity of the data along the time of acquisition.

Steve
  • 1,579
  • 10
  • 23

2 Answers2

0

Convert your hh:mm:ss to datenum -- probably need to add day, month,year so it is in the correct order you want it. Then you can just set your tick to be HH:MM:SS or seconds or whatever you need. Look here: https://www.mathworks.com/help/matlab/ref/datetick.html

Flynn
  • 269
  • 2
  • 12
0

From 2014b you can use datetime.

Choose either the actual dates of recording, or some arbitrary dates which are one day apart, and assign the date part to your data like

% Create 3 random time arrays of the format 'hh:mm:ss'
t = [randi([10,14], 10,1), randi([0,59], 10,1), randi([0,59], 10,1)];
T1 = [num2str(t(:,1), '%02i'), repmat(':', 10, 1), num2str(t(:,2), '%02i'),repmat(':', 10, 1), num2str(t(:,3), '%02i')];
t = [randi([10,14], 10,1), randi([0,59], 10,1), randi([0,59], 10,1)];
T2 = [num2str(t(:,1), '%02i'), repmat(':', 10, 1), num2str(t(:,2), '%02i'),repmat(':', 10, 1), num2str(t(:,3), '%02i')];
t = [randi([10,14], 10,1), randi([0,59], 10,1), randi([0,59], 10,1)];
T3 = [num2str(t(:,1), '%02i'), repmat(':', 10, 1), num2str(t(:,2), '%02i'),repmat(':', 10, 1), num2str(t(:,3), '%02i')];

% Convert to dates on consecutive days
D1 = datetime(strcat('2000-01-01-', T1), 'inputformat', 'yyyy-MM-dd-HH:mm:ss');
D2 = datetime(strcat('2000-01-02-', T1), 'inputformat', 'yyyy-MM-dd-HH:mm:ss');
D3 = datetime(strcat('2000-01-03-', T1), 'inputformat', 'yyyy-MM-dd-HH:mm:ss');

% Plot
data = rand(30,1);
plot([D1, D2, D3], data);
Wolfie
  • 27,562
  • 7
  • 28
  • 55