Count up instead of down?

Hello All! I have this snippet ofcode:
r=get(mp.currentMedia,'duration');
remaint=r-currpos1;
set(handles.edit2,'String',remaint);
Basically, it gets the "duration" of the currently selected video in a GUIDE GUI in seconds, then -1 it by 1 and sends the value to an edittext.
Problem is it counts down 40, 39, 38... instead of up. I'm trying to figure out a way to modify this code so it counts from 0 to "duration"
Thanks!

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 8월 4일

1 개 추천

If remaint counts as 40, 39, 38... then simply currpos1 will count 0, 1, 2...

댓글 수: 9

B_Richardson
B_Richardson 2011년 8월 4일
so lose the "r-" ? I'm gonna try that now
Oleg Komarov
Oleg Komarov 2011년 8월 4일
Might not work but then I need to know what are the values of r and currpos1 at the beginnign of the iteration.
B_Richardson
B_Richardson 2011년 8월 4일
Hmmm, that did quite work. Maybe I should share more of the code:
currpos=mp.controls.currentPosition; %this probably doesnt matter
pause(1);
r=get(mp.currentMedia,'duration'); %this r is important
set(handles.slider3,'max',r) %uses r
for i=currpos:r
j=get(handles.edit1,'String');
set(mp.settings,'playCount',str2double(j));
currpos1=mp.controls.currentPosition;
index_selected1 = get(handles.listbox1,'Value');
pause(1);
r=get(mp.currentMedia,'duration');
remaint=currpos1;
set(handles.edit2,'String',remaint);
j=0;
if remaint <=0 || j==r
break;
end
end
I'll admit this is not my code but I'm sure this is where I need to make changes
B_Richardson
B_Richardson 2011년 8월 4일
So the key party is:
r=get(mp.currentMedia,'duration');
remaint=currpos1; %this used to be remaint=r-currpos1; But I changed it
%but it still counts down
set(handles.edit2,'String',remaint);
I know that "r" has the length of the video
B_Richardson
B_Richardson 2011년 8월 4일
Oooops I meant "didnt* quite work" at the top
Oleg Komarov
Oleg Komarov 2011년 8월 4일
Are you sure you want to count it down? if remaint <= 0 will be verified immediately and will get out of the loop.
anyways: remaint = i-currpos;
B_Richardson
B_Richardson 2011년 8월 4일
"Are you sure you want to count it down?" No I want to count up. 0,1,2,3...
I will try this out!
Oleg Komarov
Oleg Komarov 2011년 8월 4일
Ehm...I wanted to ask if "are you sure you want to count it up since ..."
B_Richardson
B_Richardson 2011년 8월 4일
I made the change, it still seems to count down.

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Image Analyst
Image Analyst 2011년 8월 4일

1 개 추천

I don't know what this means "...then -1 it by 1 ..." If r is the total time of the video, and currpos1 is the elapsed time, then remaint is the remaining time, and of course that will count down as you observed. The longer it plays, the less time there is left. If you want it to show elapsed time instead of remaining time, just send currpos1 to the static text label instead of remaint. The elasped time will, of course, count up.

댓글 수: 2

B_Richardson
B_Richardson 2011년 8월 4일
set(handles.edit2,'String',currpos1);
Still the edittext counts down. There must be something else going on here.
B_Richardson
B_Richardson 2011년 8월 4일
"...then -1 it by 1 ..."
I meant subtract by 1.
r=get(mp.currentMedia,'duration');
remaint=r-currpos1;
set(handles.edit2,'String',remaint);
I dont see why what you suggested wouldnt work. Cleary the edittext's value is remaint

댓글을 달려면 로그인하십시오.

B_Richardson
B_Richardson 2011년 8월 4일

0 개 추천

If you want to see the code yourself, I got it here
Its in the callback for pushbutton2
B_Richardson
B_Richardson 2011년 8월 4일

0 개 추천

Actually everyone, I learned that the edit2 was being updated at another place in the code. After I changed that to
set(handles.edit2,'String',currpos1);
The counter starts at the beginning, but doesn't count at all. I'm sure if I had a better handle on the Matlab debugger I could figure this out
B_Richardson
B_Richardson 2011년 8월 4일

0 개 추천

Figured it out! Image Analyst was right!
remaint=currpos1;
set(handles.edit2,'String',remaint);
j=0;
if remaint <=0 j==r %had to change "remaint" to "currpos1" here
Thanks for the help. I think I'm finally starting to get good with Matlab.

카테고리

도움말 센터File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by