Video seek for Stackedplot
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
Is there MATLAB functional which helps us to seek through the stackedplot graph.
stackedplot(data)
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure
set(findall(gcf,'-property','FontSize'),'FontSize',10); % Adjust font size
fig_name = fullfile(parent_folder, sprintf('%s_Figure.jpg', folder_name));
saveas(gcf, fig_name, 'jpeg');
% Create a VideoWriter object for the current subfolder
video_name = fullfile(parent_folder, [folder_name '_video.mp4']);
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
running this, the code gets out of the function with out stating an error
Error using parentdirectory
Expected input to be a non-missing string scalar or character vector.
Error in untitled11 (line 9)
parentdirectory(parent_folder_path);
Thanks,
Bhargav
0 Commenti
Risposte (1)
Shubham
il 21 Mar 2024
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!
0 Commenti
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!