Creating a time input dialog and plotting in the time period.
10 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
VBBV
2020-11-2
编辑:VBBV
2020-11-2
You have additional ] at the end of input box. Plus you have defined st and at as structure. Define them outside the if condition.
% if true
% code
%end
answer = questdlg('is there a time stamp available? y = yes, n = no',...
'input',...
'y','n','n');
if (answer == 'y')
% st.Format='hh:mm:ss'; % place this after input box
% et.Format='hh:mm:ss';
st = input( ' Please add the starttime in [HH:MM:SS] ') % here
et = input( ' Please add the endtime in [HH:MM:SS] ')% here
end
更多回答(1 个)
Mathieu NOE
2020-11-2
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!