I have a question about time. Suppose the start time of a movie is 12:35 and the duration of the movie is 125 minutes. Is there any function in MATLAB that shows the finish time of the movie? Thanks

I have a question about time. Suppose the start time of a movie is 12:35 and the duration of the movie is 125 minutes. Is there any function in MATLAB that shows the finish time of the movie? Thanks

 Accepted Answer

If you have R2014b or later, use the duration function:
H = 12;
MI = 35+[0:125];
S = 0;
D = duration(H,MI,S);
MovieStart = D(1)
MovieFinish = D(end)
produces:
MovieStart =
12:35:00
MovieFinish =
14:40:00

8 Comments

My pleasure!
I had not used the duration function in that way before, so I learned something.
Hi Do you mind if I ask another question. I want to create a persistent variable acting as a buffer. When i enter the input x several times it stores the inputs? Thanks
Persistent variables are known only to the function in which they are used. I don’t use them much, but you could certainly change them if they are scalars, and add elements to them if they are vectors or matrices. They would retain all the information in them between function calls.
It is a question. What is the command so it shows what already have been stored in the variable?
Variables in functions, including persistent variables, are local to the functions that use them. Returning the content of a persistent variable as a function output does not change it, but will put it in your script workspace so you can see it and use it. So the easiest way is to put it as an output to your function, for example:
function [B,x] = myfun(A)
persistent x
x = size(A)
B = A*A';
end
then call your function as:
[B,x] = myfun(A);
to see what x is as the result of that function call.
Experiment with it to get the result you want.
Sorry I tried the code but it gives error. What is B = A*A' for? Thanks
It’s been a while since i used persistent variables.
This works:
function [B,y] = myfun(A)
persistent x
x = size(A)
B = A*A';
y = x;
end
The call to it is the same.
The
B = A*A';
is just to give it something to do.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!