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
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
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
Thank you. It was helpful.
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.
More Answers (0)
Categories
Find more on Entering Commands in Help Center and File Exchange
See Also
on 1 May 2015
on 2 May 2015
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)