MATLAB: Find Time when two conditions are met in two colomns

arraysindexMATLABpeak valuepercentile

I have data set
Colomn 1= Time in micro seconds
Colomn 2 = Negative voltage
Colomn 3 = Out put current pulse
(1) How to get Time when Current is 50% after max negative voltage is applied BEFORE peak Current (MAX)
(2) How to get Time when Current is 50% after max negaitve voltage is applied AFTER Peak Current (MAX)
clear
data =load('Data1.txt');
Time=data(:,1);
Voltage=data(:,2);
Current=data(:,3);

Best Answer

Really don't need the applied signal at all to answer the Q?...
data=load('Data1.txt');
[Imx,iImx]=max(data(:,3)); % find, locate peak
ixRise=find(data(:,3)>=Imx/2,1,'first'); % and rise and
ixFall=find(data(:,3)>=Imx/2,1,'last'); % fall locations...
The above has the granularity of the sampling rate; you could also then use interp1 intersection to get and find the actual intersection if that much precision is needed.
fmt="Peak time (msec): %.1f, Max I: %.3f\n50%% TRise (msec): %.1f TFall(msec): %.1f\n";
>> fprintf(fmt,data(iImx,1)*1E6,Imx, data(ixRise,1)*1E6, data(ixFall,1)*1E6)
Peak time (msec): 39.6, Max I: 59.474
50% TRise (msec): 18.6 TFall(msec): 41.2
>> (maxk(data(:,3),10)) % Inspect peak current area --
ans =
59.4738
57.0392
57.0392
57.0392
57.0392
56.6914
56.3436
56.3436
56.3436
56.3436
>>
One might consider using an average or smoothing instead of the one-point maximum above...for at least this dataset, there are five values at the plateau with just the one spike that is the actual peak max that may well be tied in with the change in input? That's a little more involved, but above gives the idea.
plot(data(:,1),[data(:,2)/100 data(:,3)]) % scale applied signal to be able to see detail easily
ylim([-20 70]) % and set appropriate y range
yline(Imx/2,'r:','HalfMax');
plot(data(ixRise,1),Imx/2,'r*')
plot(data(ixFall,1),Imx/2,'r*')
Of course, should plot and examine first before doing anything...above yields