Creating a time input dialog and plotting in the time period.
Show older comments
I would like to plot specific variables with their time and values, that have been saved and imported from Excel. Which I already did.
Now I have to add a new part in the code, which is adding an input dialog where I can write a time stamp or period which the variable would only be plotted between the start time (st) and the end time (et) in the "HH:MM:SS" format that have been written in the dialog. I tried the code below and I got the following error for the two last disp lines of the inputbox.
Error using horzcat
The following error occurred converting from char to struct:
Conversion to struct from char is not possible.
Is there a way how write the two start and end times and plot the variables ( which are written in the U variable) only in the time stamp that was put in the dialog box?
answer = questdlg('is there a time stamp available? y = yes, n = no',...
'input',...
'y','n','n');
if (answer == 'y')
st.Format='hh:mm:ss';
et.Format='hh:mm:ss';
st = input( ' Please add the starttime in [HH:MM:SS] '])
et = input( ' Please add the endtime in [HH:MM:SS] '])
end
S = load('matlabtable.mat');
T = S.HV801000front10Vml2;
U = {'E1_ABD_FoamEventCnt','E1_LD_ActualStatus','H1_PRESSURE_S15hPa'};
for k = 1:numel(U)
X = T.Variable==U(k);
Wert = T.Value(X);
Uhrzeit = round(seconds(T.time(X)/1000));
Uhrzeit.Format='hh:mm:ss';
Uhrzeit = sort( Uhrzeit,'ascend');
nexttile
plot(T.time(X),T.Value(X))
xlabel('time')
title(char(U(k)),'Interpreter','none')
end
Accepted Answer
More Answers (1)
Mathieu NOE
on 2 Nov 2020
hello
I think there is some input dialog window missing for the start and end time inputs
I suggest the following code :
answer = questdlg('is there a time stamp available? y = yes, n = no',...
'input',...
'y','n','n');
if (answer == 'y')
prompt = {'Enter start Time indexes [HH:MM:SS]:','Enter stop Time indexes [HH:MM:SS]:'};
dlgtitle = 'Time indexes HH:MM:SS ';
dims = [1 35];
definput = {'13:20:00','13:50:00'};
time_answer = inputdlg(prompt,dlgtitle,dims,definput);
st = time_answer{1,:}; % cell of char array
et = time_answer{2,:}; % cell of char array
% st.Format='hh:mm:ss';
% et.Format='hh:mm:ss';
% disp([st ' Please add the starttime in [HH:MM:SS] '])
% disp([et ' Please add the starttime in [HH:MM:SS] '])
end
% conversion time in seconds for test in for loop below
[Y, M, D, H, MN, S] = datevec(st);
st_secs = S+MN*60+H*3600;
[Y, M, D, H, MN, S] = datevec(et);
et_secs = S+MN*60+H*3600;
S = load('matlabtable.mat');
T = S.HV801000front10Vml2;
U = {'E1_ABD_FoamEventCnt','E1_LD_ActualStatus','H1_PRESSURE_S15hPa'};
for k = 1:numel(U)
X = T.Variable==U(k);
Wert = T.Value(X);
time = (T.time(X)/1000);
% reduce plot to time index between start and stop
ind = find(time>= st_secs & time<= et_secs);
time = time(ind);
Wert = Wert(ind);
Uhrzeit = round(seconds(time));
Uhrzeit.Format='hh:mm:ss';
Uhrzeit = sort( Uhrzeit,'ascend');
nexttile
plot(Uhrzeit,Wert);
xlabel('time')
title(char(U(k)),'Interpreter','none')
end
1 Comment
Ramo Rafsel
on 2 Nov 2020
Edited: Ramo Rafsel
on 2 Nov 2020
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!