Error massage "Execution of script project2 as a function is not supported"

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

Also I have this error
Error in project2 (line 29)
writeObj = VideoWriter(project2,'MPGE-4');

Sign in to comment.

Answers (1)

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

I inserted your example like this but still it shows me an error
thefile = 'project2';
writerObj= VideoWriter(thefile,"MPEG-4");
sps = 0.5;
writerObj.FrameRate = sps;
Warning: No video frames were written to this file. The file
may be invalid.
> In VideoWriter/close (line 282)
In VideoWriter/delete (line 217)
In project2 (line 29)
Unrecognized function or variable 'slideFrame'.
Error in project2 (line 40)
frame = slideFrame(inputImage);
I'm so confusing right now
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.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 6 May 2022

Commented:

on 6 May 2022

Community Treasure Hunt

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

Start Hunting!