Error massage "Execution of script project2 as a function is not supported"
Show older comments
Hello, I'm creating slide show and I got 2 errors and I can't understand what are these errors. If this code needs to fix please let me know.
code is
inputIm=char('im1.jpg','im2.jpg','im3.jpg','im4.jpg');
pause on;
for i=1:size(inputIm,1)
a=imread(inputIm(i,:));
imshow(a);
drawnow;
pause(1);
end
sps = 0.5;
writerObj = VideoWriter(project2,'MPGE-4');
writerObj.FrameRate = sps;
spf = [4 8 12 16];
open(writerObj);
for i=1:size(inputIm,1)
inputImage=imread(inputIm(i,:));
frame = slideFrame(inputImage);
for numSecs=1:spf(i)
writeVideo(writerObj, frame);
end
end
writeVideo(writerObj,RBG);
close(writerObj);
1 Comment
fluffy1111
on 6 May 2022
Edited: Walter Roberson
on 6 May 2022
Answers (1)
Steven Lord
on 6 May 2022
The first input to the VideoWriter function must be the name of the video file you want to write. This could be a hard-coded char vector or string, a variable containing a char vector or string, or the output of a function call where the function returns a char vector or a string. The VideoWriter objects v1 and v2 in the example below will each create a video file named myVideo; the third will create a video file with a name selected by the user (the uiputfile function opens a file selection dialog.)
thefile = 'myVideo';
v1 = VideoWriter('myVideo') % hard-coded
v2 = VideoWriter(thefile) % variable
v3 = VideoWriter(uiputfile) % Calls the uiputfile function and uses whatever it returns
Your project2 is none of these options. It is the script file that contains the VideoWriter call that is being executed. Unlike function files, script files cannot accept input arguments and cannot return output arguments. That's the reason for the error.
Decide what you want the video file to be called and use either the hard-coded syntax or the variable syntax from the example above to create the VideoWriter object.
2 Comments
fluffy1111
on 6 May 2022
Edited: Walter Roberson
on 6 May 2022
Walter Roberson
on 6 May 2022
slideframe() is being used as a function. There is, however, no MATLAB function named slideframe . I am not able to find anyone on the internet offering a MATLAB function named slideframe . It appears to me that you were intended to provide slideframe yourself.
The warning you are seeing happens if you open a video writing session, but do not write any frames at all to the file. There are also reasons why video files can fail if you only write exactly 1 frame to them, so it is best to always write 2 or more frames to a video file.
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!