You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Unable to read file 'C:\Users\Omer\Documents\MATLAB\Automatic-Fracture-Detection-Code-1.0.0shearletSystem4.mat'. No such file or directory.
1 view (last 30 days)
Show older comments
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 Comments
Kevin Holly
on 30 Sep 2021
If you drag the file into the command window, does it provide the same file path when it loads?
Omer Iqbal
on 30 Sep 2021
No, it does not give the complete path ( Please snapshot) , i have also tried to change the path as well.
Answers (2)
Image Analyst
on 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 Comments
Omer Iqbal
on 1 Oct 2021
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>>
Image Analyst
on 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
on 2 Oct 2021
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>>
Image Analyst
on 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
on 2 Oct 2021
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>>
Omer Iqbal
on 4 Oct 2021
Edited: Walter Roberson
on 4 Oct 2021
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
Image Analyst
on 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
on 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
on 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 Comments
Walter Roberson
on 1 Oct 2021
At the time of the error, please show us
pwd()
ls()
filenane = fullfile(outfolder, sheerletSystem, i + ".mat")
exist(filename)
Omer Iqbal
on 1 Oct 2021
Edited: Image Analyst
on 1 Oct 2021
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)
Image Analyst
on 1 Oct 2021
Edited: Image Analyst
on 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
on 1 Oct 2021
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
Walter Roberson
on 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
on 1 Oct 2021
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'));
Walter Roberson
on 1 Oct 2021
fileName = fullfile(outfolder, 'sheerletSystem', i + ".mat")
load(fileName)
Omer Iqbal
on 1 Oct 2021
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>>
Walter Roberson
on 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
on 1 Oct 2021
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>>
Walter Roberson
on 1 Oct 2021
If I have followed everything properly,
fileName = fullfile(outfolder, "sheerletSystem" + i + ".mat")
load(fileName)
Omer Iqbal
on 1 Oct 2021
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'))
Walter Roberson
on 1 Oct 2021
fileName = fullfile(outfolder, "shearletSystem" + i + ".mat")
load(fileName)
"shear" instead of "sheer" ...
Omer Iqbal
on 1 Oct 2021
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>>
Omer Iqbal
on 1 Oct 2021
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>>
Walter Roberson
on 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
on 11 Oct 2021
Hi !
Thanks for helping me ! I managed to run the functions. The X was supposed to estimate using some other linked functions.
See Also
Categories
Find more on MATLAB Report Generator in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)