# if or for loop

6 views (last 30 days)
Mohammad Ariful Hoq on 13 Oct 2021
Commented: Image Analyst on 13 Oct 2021
Hello,
I am confused about this issue. i have an excel file with 2 colomn. first column is the time(hours) and second column is the power. like:
time= 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
power= 0,0,0,0,0,12,40,100,200,300,500,800,700,650,600,500,400,200,0,0,0,0,0,0
Now, I want to implement,
First: whenever the value of 'power' is greater than 0, then it will show the time (i.e 6)
Last: whenever the value of 'power' is greater than 0, then it will show the time (i.e 19)
Please give your suggestion. I have attachded the excel file. Thank you very much.

Dave B on 13 Oct 2021
You can find the index of the first and last instance of power greater than 0 using the find function, then put those indices right into time to get the values:
time= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24];
power= [0,0,0,0,0,12,40,100,200,300,500,800,700,650,600,500,400,200,0,0,0,0,0,0];
time(find(power>0,1,'first'))
ans = 6
time(find(power>0,1,'last'))
ans = 18
##### 2 CommentsShowHide 1 older comment
Image Analyst on 13 Oct 2021