Hey Bhargav,
The error message that you are encountering suggests that the input requires to be a string. You may find the following MATLAB Answer relevant to your case:
Also, for saving a file in parent directory, you can refer to the following MATLAB Answer: https://www.mathworks.com/matlabcentral/answers/175881-save-folder-one-above-current-directory
For creating a video from stackedplot, you can refer to your previous thread: https://www.mathworks.com/matlabcentral/answers/2094016-video-for-stacked-plot?s_tid=prof_contriblnk
I have modified your code snippet as follows:
% Data Generation
numDataPoints = 1500;
t = linspace(0, 10*pi, numDataPoints); % Time vector
x = 1:numDataPoints; % for xticks only
% Generating data for plotting stackedplot
data = [sin(t)' sin(2*t)' sin(0.5*t)' x'];
data = array2table(data)
stackedplot(data,'XVariable','data4')
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure
set(findall(gcf,'-property','FontSize'),'FontSize',10); % Adjust font size
% Use the current working directory as the parent folder
parent_folder = cd;
parent_folder = fullfile(parent_folder, '..');
folder_name = 'stacked_plot'; % Example folder name
% Construct the full path to the folder where the figure and video will be saved
full_path = fullfile(parent_folder, folder_name);
% Check if the folder exists, if not, create it
if ~exist(full_path, 'dir')
mkdir(full_path);
end
% Define the full file path for the figure and video
fig_name = fullfile(full_path, sprintf('%s_Figure.jpg', folder_name));
video_name = fullfile(full_path, [folder_name '_video.mp4']);
% Save the figure
saveas(gcf, fig_name, 'jpeg');
% Create a VideoWriter object for the video
v = VideoWriter(video_name, 'MPEG-4');
open(v);
% Capture the frame and add it to the video
frame = getframe(gcf);
writeVideo(v, frame);
% Close the VideoWriter object
close(v);
close(gcf); % Close the figure
You may also share your complete code.
I hope this helps!