Matlab Directory Stopped Finding File
Mostrar comentarios más antiguos
Hi,
I'm using the following code to create a video from a series of matlab files in a specific folder. Each file contains a variable which is the "Frame". I start by counting the number of files in the folder which works well and I had this whole code working perfectly yesterday. However, now matlab seems to not be able to find my files...
My main matlab script is kept in the folder: "E:\Uni\Imaging\23-11" and the files I want to load are in the subfolder "E:\Uni\Imaging\23-11\8". When I run my code matlab now says it cannot find the file. Saying
"Unable to read file 'Rec--000008_10HZ_1.mat'. No such file or
directory."
Yet the file exists and works. When run:
load("8\Rec--000008_10HZ_1.mat", "Frame")
On the command window, this works fine.
Anyone know what might cause this issue?
Thank you
%% Experiment 08 - Water Jet (7)
fprintf("Starting Experiment 8 \n\n");
%Importing All Frames for Investigation 08
folder = 'E:\Uni\Imaging\23-11\8';
files = dir(fullfile(folder, '*.mat'));
N_frames = size(files,1) - 2;
directory = 'Rec--000008_10HZ_%d.mat';
t = 0:0.1:N_frames;
% Create a VideoWriter object to write the video out to a new, different file.
writerObj = VideoWriter("test_8.avi",'Uncompressed AVI');
writerObj.FrameRate = 10; % How many frames per second.
open(writerObj);
% Need to change from the default renderer to zbuffer to get it to work right.
% openGL doesn't work and Painters is way too slow.
set(gcf, 'renderer', 'zbuffer');
%% Create the movie.
% After this loop starts, BE SURE NOT TO RESIZE THE WINDOW AS IT'S SHOWING THE FRAMES, or else you won't be able to save it.
%Import frames
for frameIndex = 1:800 %To number of frames N_frames (after 800 frames are useless)
cla reset;
filename = sprintf(directory, frameIndex);
load(filename, "Frame"); %Check if files exists
%Absolute Frame Post Process
currentFrame = Frame - min(Frame(:));
imagesc(currentFrame);
caption = sprintf('Experiment 8: Frame #%d of %d, t = %.1f', frameIndex, N_frames, t(frameIndex));
title(caption, 'FontSize', 15);
colorbar
thisFrame = getframe(gcf);
%Write this frame out to a new video file.
writeVideo(writerObj, thisFrame);
end
close all;
close(writerObj);
Respuesta aceptada
Más respuestas (1)
Afonso Espírito Santo
el 5 de Abr. de 2022
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!