Unable to read file 'C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0shearletSystem4.mat'. No such file or directory.
Afficher commentaires plus anciens
Hellow everyone!
I am running a code to detect the fractures from image, in the mide of code, it asks me to load the mat file generated by this function, the mat file is present in the folder but still giving me an error that no file exisit.
Any suggestion?
2 commentaires
Kevin Holly
le 30 Sep 2021
If you drag the file into the command window, does it provide the same file path when it loads?
Omer Iqbal
le 30 Sep 2021
Réponses (2)
Image Analyst
le 1 Oct 2021
Run this code.
topLevelFolder = 'C:\Users\Omer\Documents\MATLAB';
filePattern = fullfile(topLevelFolder, '**\*.mat')
fileList = dir(filePattern)
% Loop over them.
numFiles = length(fileList);
for k = 1 : numFiles
thisFileName = fullfile(fileList(k).folder, fileList(k).name);
fprintf('File #%d of %d :\n "%s"\n', k, numFiles, thisFileName);
% Get size info if desired
d = dir(thisFileName);
fprintf(' It is %d bytes.\n', d.bytes);
s = load(thisFileName)
end
What do you see in the command window?
9 commentaires
Omer Iqbal
le 1 Oct 2021
Image Analyst
le 2 Oct 2021
OK, now we're getting somewhere. It's definitely finding your files now. Now you simply need to get the variable from the structure and do something with it.
topLevelFolder = 'C:\Users\Omer\Documents\MATLAB';
filePattern = fullfile(topLevelFolder, '**\*.mat')
fileList = dir(filePattern)
% Loop over them.
numFiles = length(fileList);
for k = 1 : numFiles
thisFileName = fullfile(fileList(k).folder, fileList(k).name);
fprintf('File #%d of %d :\n "%s"\n', k, numFiles, thisFileName);
% Get size info if desired
d = dir(thisFileName);
fprintf(' It is %d bytes.\n', d.bytes);
s = load(thisFileName)
% Get the shearletSystem structure:
shearletSystem = s.shearletSystem;
% Now do something with shearletSystem.....
end
What do you want to do with the shearletSystem variable?
Omer Iqbal
le 2 Oct 2021
Image Analyst
le 2 Oct 2021
One of your mat files does not have that variable in it. You might need to adjust your file pattern, like
filePattern = fullfile(topLevelFolder, '**\sh*.mat')
or something.
Omer Iqbal
le 2 Oct 2021
Image Analyst
le 3 Oct 2021
How did you define X?
Omer Iqbal
le 4 Oct 2021
Modifié(e) : Walter Roberson
le 4 Oct 2021
Image Analyst
le 4 Oct 2021
When you do
X = fftshift(fft2(ifftshift(X)));
it takes X and does operations on it and puts it back into X. So X must exist already. You must define it before you call that line.
Walter Roberson
le 4 Oct 2021
The error messages show that CSHRMsheardec needs to be called with at least one parameter, that it refers to as X, but that you ran the function with no parameters -- for example you might have pressed the green Run button instead of going down to the command line and invoking the function passing in values.
Walter Roberson
le 30 Sep 2021
Do not use strcat() to create the path like that: you are missing a directory separator. Use
load( fullfile(outfolder, sheerletSystem, i + ".mat") )
18 commentaires
Omer Iqbal
le 1 Oct 2021
Walter Roberson
le 1 Oct 2021
At the time of the error, please show us
pwd()
ls()
filenane = fullfile(outfolder, sheerletSystem, i + ".mat")
exist(filename)
Omer Iqbal
le 1 Oct 2021
Modifié(e) : Image Analyst
le 1 Oct 2021
Image Analyst
le 1 Oct 2021
Modifié(e) : Image Analyst
le 1 Oct 2021
OK, filenane is a different variable than filename. The first one does not have an "m" in it.
Try this:
workspace; % Show all variables
fileName = fullfile(outfolder, 'shearletSystem',num2str(i),'.mat')
isfile(fileName)
Omer Iqbal
le 1 Oct 2021
Walter Roberson
le 1 Oct 2021
fileName = fullfile(outfolder, sheerletSystem, i + ".mat")
Notice I do not use num2str(). Notice no comma between the i and the .mat . Notice I use + ".mat" which is string() concatenation
Is there a particular reason to use num2str(i) instead of using the way I show? For example are you using R2016b or earlier, in which case you might have problem access string() objects ?
Omer Iqbal
le 1 Oct 2021
Walter Roberson
le 1 Oct 2021
fileName = fullfile(outfolder, 'sheerletSystem', i + ".mat")
load(fileName)
Omer Iqbal
le 1 Oct 2021
Walter Roberson
le 1 Oct 2021
Now I am confused about your directory structure. Please show
ls('C:\Users\Omer\Documents\MATLAB\*.mat')
ls('C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\*.mat')
ls('C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\sheerletSystem\*.mat')
Omer Iqbal
le 1 Oct 2021
Walter Roberson
le 1 Oct 2021
If I have followed everything properly,
fileName = fullfile(outfolder, "sheerletSystem" + i + ".mat")
load(fileName)
Omer Iqbal
le 1 Oct 2021
Walter Roberson
le 1 Oct 2021
fileName = fullfile(outfolder, "shearletSystem" + i + ".mat")
load(fileName)
"shear" instead of "sheer" ...
Omer Iqbal
le 1 Oct 2021
Omer Iqbal
le 1 Oct 2021
Walter Roberson
le 4 Oct 2021
I do not seem to find a complete posting of your code, for us to see where you define outfolder . In the previous comments, you never posted that part so we just had to assume that you had already defined it.
Omer Iqbal
le 11 Oct 2021
Catégories
En savoir plus sur Scope Variables and Generate Names dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
