I want to set time when i plot graph (in gui)

when i put
09:12:45 ->Edit text 1
12:00:12 ->Edit text 2
i want to plot graph between text 1 and text 2 time
is it possible?
at first i imported data from excel

 Accepted Answer

If you convert to a timetable() object then you can use timerange() to subscript the entries.
If you do not use a timetable() object, then you can use standard logical masks, like
start_dur = duration( get(handles.text1, 'String') );
end_dur = duration( get(handles.text2, 'String') );
dur_column = YourArray{:,3}; %select appropriate duration column, method will vary according to how you stored your data
mask = dur_column >= start_dur & dur_column <= end_dur;
selected_data = YourArray{mask, :}; %method will vary according to how you stored your data
Now you can plot from selected_data

13 Comments

what is Yourarray{:,3}??? 3 mean?
I had to guess about how you were storing your data. One of the ways that permits data of different types to be represented is to use table() objects. When you use a table() object named YourArray, then the syntax YourArray{:,3} would mean that you wanted to extract the contents of column 3 of YourArray. Here the 3 was chosen arbitrarily for illustration purposes, as I do not know how your data is arranged.
If you are using a cell array instead of a table, then if each cell contains a single duration, then you would instead use a syntax such as
dur_column = cell2mat(YourArray(:,3));
or, equivalently (and more efficiently)
dur_column = vertcat(YourArray{:,3});
When you use a cell array, YourArray{5,3} would mean to extract the content stored at cell row 5 column 3; the content itself might be any size or data type.
 handles.fileName=uigetfile('*.xls');
 fileName=handles.fileName;
 [~,txt,~]=xlsread(fileName,'C27:C30000');   
 [Ch1,~,~]=xlsread(fileName,'E27:E30000');
 [Ch2,~,~]=xlsread(fileName,'F27:F30000');
 [Ch3,~,~]=xlsread(fileName,'G27:G30000');
 [Ch4,~,~]=xlsread(fileName,'H27:H30000');
 [Ch5,~,~]=xlsread(fileName,'I27:I30000');
 [Ch6,~,~]=xlsread(fileName,'J27:J30000');
 [Ch7,~,~]=xlsread(fileName,'K27:K30000');
 [Ch8,~,~]=xlsread(fileName,'L27:L30000');
 [Ch9,~,~]=xlsread(fileName,'M27:M30000');
 [Ch10,~,~]=xlsread(fileName,'N27:N30000');
 [Ch11,~,~]=xlsread(fileName,'O27:O30000');
 [Ch12,~,~]=xlsread(fileName,'P27:P30000'); 
 [Ch13,~,~]=xlsread(fileName,'Q27:Q30000');
 [Ch14,~,~]=xlsread(fileName,'R27:R30000');
 [Ch15,~,~]=xlsread(fileName,'S27:S30000');
 [Ch16,~,~]=xlsread(fileName,'T27:T30000');
 [Ch17,~,~]=xlsread(fileName,'U27:U30000');
 [Ch18,~,~]=xlsread(fileName,'V27:V30000');
 [Ch19,~,~]=xlsread(fileName,'W27:W30000');
 [Ch20,~,~]=xlsread(fileName,'X27:X30000');
 char(txt);   %txt is time 
 DateNumber=datenum(txt);
 Date=datetime(DateNumber,'ConvertFrom', 'excel');  
 Date1=datetime(Date,'Format','hh:mm:ss');

i use datetime type

I am having to guess here about what is stored in column C, as your code is a bit contradictory.
handles.fileName=uigetfile('*.xls');
fileName=handles.fileName;
[~,txt,~]=xlsread(fileName,'C27:C30000');
Ch = xlsread(fileName,'E27:X30000');
Date1 = duration(txt, 'InputFormat', 'hh:mm:ss', 'Format', 'hh:mm:ss');
start_dur = duration( get(handles.text1, 'String') );
end_dur = duration( get(handles.text2, 'String') );
mask = Date1 >= start_dur & Date1 <= end_dur;
selected_Ch = Ch(mask, :);
09:02:50
09:02:52
09:02:54
09:02:56
this is in column C . it's like hh:mm:ss format. and i will plot each channel in one figure. and i'll use check box .and then i can select channel that i want to see or not
Then the code I posted will probably work.
You can access the channels as selected_Ch(:, CHANNEL_NUMBER)
ok i'll try and if it doesnt'work i'll ask u again
it doesn't work .duration line error occurr . error message: input data should be 3 columns numeric arrays i think 09:12:24 is just string format (like text)
Which release are you using? If I recall correction, duration() was improved as of R2018a.
Change
Date1 = duration(txt, 'InputFormat', 'hh:mm:ss', 'Format', 'hh:mm:ss');
start_dur = duration( get(handles.text1, 'String') );
end_dur = duration( get(handles.text2, 'String') );
to
Date1 = datetime(txt, 'InputFormat', 'hh:mm:ss', 'Format', 'hh:mm:ss');
start_dur = duration( get(handles.text1, 'String') );
end_dur = duration( get(handles.text2, 'String') );
Date1 = Date1 - dateshift(Date1, 'start', 'day');
start_dur = start_dur - dateshift(start_dur, 'start', 'day');
end_dur = end_dur - dateshift(end_dur, 'start', 'day');
it doesn't work.duration function still have problem. dateshift are not working with duration function
how about using datetime instead of duration
Date1 = datetime(txt, 'InputFormat', 'hh:mm:ss', 'Format', 'hh:mm:ss');
start_dur = datetime( get(handles.text1, 'String') );
end_dur = datetime( get(handles.text2, 'String') );
Date1 = Date1 - dateshift(Date1, 'start', 'day');
start_dur = start_dur - dateshift(start_dur, 'start', 'day');
end_dur = end_dur - dateshift(end_dur, 'start', 'day');

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!