Unable to read file 'C:\Users\​Omer\Docum​ents\MATLA​B\Automati​c-Fracture​-Detection​-Code-1.0.​0shearletS​ystem4.mat​'. No such file or directory.

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

If you drag the file into the command window, does it provide the same file path when it loads?
No, it does not give the complete path ( Please snapshot) , i have also tried to change the path as well.

Connectez-vous pour commenter.

Réponses (2)

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

Should I use your code instaead of fileName = fullfile(outfolder, "shearletSystem" + i + ".mat")
load(fileName). Well, I used your code in command window and have got the following information;
K>> 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
filePattern =
'C:\Users\Omer\Documents\MATLAB\**\*.mat'
fileList =
9×1 struct array with fields:
name
folder
date
bytes
isdir
datenum
File #1 of 9 :
"C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0shearletSystem1.mat"
It is 23127 bytes.
s =
struct with fields:
shearletSystem: [1×1 struct]
File #2 of 9 :
"C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0shearletSystem2.mat"
It is 23165 bytes.
s =
struct with fields:
shearletSystem: [1×1 struct]
File #3 of 9 :
"C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0shearletSystem3.mat"
It is 23165 bytes.
s =
struct with fields:
shearletSystem: [1×1 struct]
File #4 of 9 :
"C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0shearletSystem5.mat"
It is 23165 bytes.
s =
struct with fields:
shearletSystem: [1×1 struct]
File #5 of 9 :
"C:\Users\Omer\Documents\MATLAB\smallimg.mat"
It is 486 bytes.
s =
struct with fields:
img: [10×10×3 uint8]
File #6 of 9 :
"C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\Automatic-Fracture-Detection-Code-1.0.0shearletSystem4.mat.mat"
It is 23165 bytes.
s =
struct with fields:
shearletSystem: [1×1 struct]
File #7 of 9 :
"C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\shearletSystem1.mat"
It is 23127 bytes.
s =
struct with fields:
shearletSystem: [1×1 struct]
File #8 of 9 :
"C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\shearletSystem2.mat"
It is 23165 bytes.
s =
struct with fields:
shearletSystem: [1×1 struct]
File #9 of 9 :
"C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\shearletSystem3.mat"
It is 23165 bytes.
s =
struct with fields:
shearletSystem: [1×1 struct]
K>>
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?
Hi!
It didnot give me an error of missing file, it generated the file and have managed to load the mat files. It seems the issue has been resolved. However, after using your code, I gor another error of incomplete input arguments in another related functions. Please have a look in snapshot and see the informtaion below that I got after using your code;
Unrecognized field name "shearletSystem".
17 X = fftshift(fft2(ifftshift(X)));
>> CSHRMsheardec
Not enough input arguments.
Error in CSHRMsheardec (line 17)
X = fftshift(fft2(ifftshift(X)));
K>>
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.
I am getting the same error after adjsuting the file pattern using your code (filePattern = fullfile(topLevelFolder, '**\sh*.mat'). Please see the following information and snapshot;
CSHRMsheardec
filePattern =
'C:\Users\Omer\Documents\MATLAB\**\sh*.mat'
Not enough input arguments.
Error in CSHRMsheardec (line 18)
X = fftshift(fft2(ifftshift(X)));
K>>
I am using someone' else codes, I am trying to use inverse fourier trasnform and fourier trasnform shift on deveopled shearlets. I am not quite familiar on how to implement fftshift , fft2 and ifftshift. Below are the codes that I am trying to use. Additionally, there are some other functions which depend on these codes as well. X must be shearlets!
X = fftshift(fft2(ifftshift(X)));
for k = 1:contShearletSystem.nShearlets
coeffs(:,:,k) = conj(fftshift(ifft2(ifftshift(X.*conj(contShearletSystem.nshearlets(:,:,k))))));
end
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.
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.

Connectez-vous pour commenter.

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

Hi! I tried to use your code but it giving me same error.
At the time of the error, please show us
pwd()
ls()
filenane = fullfile(outfolder, sheerletSystem, i + ".mat")
exist(filename)
I got the following information. Please also see attached snapshot.
pwd
ans =
'C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0'
K>> filenane = fullfile(outfolder, 'shearletSystem',num2str(i),'.mat'));
filenane = fullfile(outfolder, 'shearletSystem',num2str(i),'.mat'));
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
K>> filenane = fullfile(outfolder, 'shearletSystem',num2str(i),'.mat')
filenane =
'C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\shearletSystem\1\.mat'
K>> exist(filename)
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)
I have got following information;
K>> workspace; % Show all variables
fileName = fullfile(outfolder, 'shearletSystem',num2str(i),'.mat')
isfile(fileName)
fileName =
'C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\shearletSystem\1\.mat'
ans =
logical
0
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 ?
I am using R2021a. I tried to use your code but it didnot work, please see the information below that I got using your code:
workspace; % Show all variables
fileName = fullfile(outfolder, sheerletSystem, i + ".mat")
isfile(fileName)
Unrecognized function or variable 'sheerletSystem'.
188 load( fullfile(outfolder, 'shearletSystem',num2str(i),'.mat'));
K>> workspace; % Show all variables
fileName = fullfile(outfolder, sheerletSystem, i + ".mat")
isfile(fileName)
Unrecognized function or variable 'sheerletSystem'.
188 load( fullfile(outfolder, 'shearletSystem',num2str(i),'.mat'));
fileName = fullfile(outfolder, 'sheerletSystem', i + ".mat")
load(fileName)
load( fullfile(outfolder, 'shearletSystem',num2str(i),'.mat'));
K>> fileName = fullfile(outfolder, 'sheerletSystem', i + ".mat")
load(fileName)
fileName =
"C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\sheerletSystem\1.mat"
Error using load
Unable to read file 'C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\sheerletSystem\1.mat'. No such file or
directory.
188 load( fullfile(outfolder, 'shearletSystem',num2str(i),'.mat'));
K>>
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')
I have got following information for each code:
K>> ls('C:\Users\Omer\Documents\MATLAB\*.mat')
Automatic-Fracture-Detection-Code-1.0.0shearletSystem1.mat Automatic-Fracture-Detection-Code-1.0.0shearletSystem5.mat
Automatic-Fracture-Detection-Code-1.0.0shearletSystem2.mat smallimg.mat
Automatic-Fracture-Detection-Code-1.0.0shearletSystem3.mat
K>> ls('C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\*.mat')
Automatic-Fracture-Detection-Code-1.0.0shearletSystem4.mat.mat shearletSystem3.mat
shearletSystem1.mat
shearletSystem2.mat
K>> ls('C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\sheerletSystem\*.mat')
No matches for pattern 'C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\sheerletSystem\*.mat'.
K>>
If I have followed everything properly,
fileName = fullfile(outfolder, "sheerletSystem" + i + ".mat")
load(fileName)
Yes, you have mentioned all the information; but I am still getting the error, please see below;
fileName = fullfile(outfolder, "sheerletSystem" + i + ".mat")
load(fileName)
fileName =
"C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\sheerletSystem1.mat"
Error using load
Unable to read file 'C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0\sheerletSystem1.mat'. No such file or
directory.
188 load( fullfile(outfolder, 'shearletSystem',num2str(i),'.mat'))
fileName = fullfile(outfolder, "shearletSystem" + i + ".mat")
load(fileName)
"shear" instead of "sheer" ...
After using your code above, I am getting a new error along with the load error. Please see snapshot and information below;
lapsed time is 0.027184 seconds.
Computing complex shearlet system based on the inputs for combination number: 3
Elapsed time is 0.022526 seconds.
Elapsed time is 0.022632 seconds.
The total number of ridge realizations is: 1750
Select multiple image files (they must be in a single folder)
You have selected 1 images
Error using fullfile (line 67)
All inputs must be strings, character vectors, or cell arrays of character vectors.
Error in Ridge_Ensemble_Generator (line 188)
load(fullfile(outfolder, shearletSystem, i + ".mat"));
67 error(message('MATLAB:fullfile:InvalidInputType'));
K>>
When I used in command window, I got follwoing information;
K>> fileName = fullfile(outfolder, "shearletSystem" + i + ".mat")
load(fileName)
Unrecognized function or variable 'outfolder'.
67 error(message('MATLAB:fullfile:InvalidInputType'));
K>>
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.
Hi !
Thanks for helping me ! I managed to run the functions. The X was supposed to estimate using some other linked functions.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Scope Variables and Generate Names dans Centre d'aide et File Exchange

Commenté :

le 11 Oct 2021

Community Treasure Hunt

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

Start Hunting!

Translated by