'.' is not an internal or external command, nor is it a runnable program or batch file
Show older comments
this below is raw2jpeg.m:
function raw2jpeg(lfp_file)
cd('lfptools') ;
sys_command = ['./lfpsplitter ../' lfp_file];
system(sys_command,'-echo') ;
cd('..') ;
[lfp_folder, lfp_path , ~] = fileparts(lfp_file) ;
lfp_path = [lfp_folder '/' lfp_path] ;
fin = fopen(strcat(lfp_path, '_imageRef0.raw'), 'r') ;
meta = fopen(strcat(lfp_path, '_metadataRef0.txt'), 'r') ;
for i = 1:3
fgets(meta);
end
fgets(meta, 12)
width = fscanf(meta, '%d') ;
fgets(meta) ;
fgets(meta, 12) ;
height = fscanf(meta, '%d') ;
I = fread(fin, width*height, 'uint16=>uint16') ;
im_in = reshape(I, height, width) ;
im_in = im_in' ;
delete([lfp_path '_imageRef0.raw'], [lfp_path '_metadataRef0.txt'], ...
[lfp_path '_privateMetadataRef1.txt'], [lfp_path '_table.txt']) ;
im_in = im_in.*1.5 ;
imwrite(im2uint8(im_in), strcat(lfp_path,'.jpg')) ;
end
The code below is an example for raw2jpeg.m:
raw2jpeg('../input/dataset/raw.lfp'); (just one row)
And the result shows like this:
'.' is not an internal or external command, nor is it a runnable program or batch file
Incorrect use of fgets
The file identifier is invalid. Generate a valid file identifier using fopen (the error exists in line 11 of raw2jpeg.m)
2 Comments
Bjorn Gustavsson
on 16 Sep 2019
What happens if you give the full path to your lfpsplitter program?
Have you tried to run the code line by line? With something like dbstop in raw2jpeg set on the command-line?
Rik
on 16 Sep 2019
It looks like you're getting an error in your system call, which then breaks the assumptions of the later code.
Answers (2)
Guillaume
on 16 Sep 2019
2 votes
First use fullfile to build paths instead of string concatenation and adding the path separator yourself. It would be more reliable.
Ther are many potential failure points in your code and you never check that anything works as you expected, so it shouldn't be surprising that you can get obscure errors.
In the first line of your function, you change to the lfptools directory relative to the current one. If the current directory is not the one you expected or if there's no lfptools directory in the current directory, the cd will fail. Note that there is never any reason to cd anywhere. Using absolute paths guarantees you that the folder you target is the one you meant regardless of what the current directory is.
You then assume that lfpsplitter has run succesfully and created two files with a given name. You never check that it is indeed the case. If it failed or for some reason named the files differently your fopen calls will fail to open the file. As a result the fin or meta file identifier will be invalid and as soon as you try to use it, you'll get an error. This is clearly what is happening here, your meta file identifier is invalid, so the first time you try to use it with fgets you get an error. Most likely the raw_metadataRef0.txt file does not exist (or can't be open for a reason or another).
When dealing with files always check that your operation actually succeeded. After a fopen check the file id is valid (i.e. positive), after a fread check that you've read the number of bytes you expected, etc.
Also, make sure that you call fclose before attempting to delete a file you've been reading/writing to. As it is, your delete call will always fail since you've still got fin and meta open.
11 Comments
Huadong Hu
on 16 Sep 2019
Bjorn Gustavsson
on 16 Sep 2019
Then the advice is: at the command-line type:
>> dbstop in raw2jpeg
Then run the command like you use to.
>> raw2jpeg('../input/dataset/raw.lfp');
That will give you a command-line prompt
K>>
This will make it possible for you to inspect all variables (plot, modify and what not), and step forward in the excecution (either by typing dbstep at the command-line or pushing the "step" button in the editor). This way you'll be able to check that everything proceeds as intended step by step in the function.
Huadong Hu
on 16 Sep 2019
Edited: Huadong Hu
on 16 Sep 2019
There is no for loop in the code you've shown (edit: sorry there is, but the rest of this sentence is still valid) and the error you're now showing has nothing to do with the function itself. Possibly you've pasted the code of the function in a script and are using an old version of matlab where functions are not allowed in scripts.
As I explained, the most likely cause for the error you initially reported is that the files raw_imageRef0.raw or raw_metadataRef0.txt do not exist. So, have you checked that?
"the code is from the toolkit which was downloaded from GitHub , so it is difficult to change the code myself"
As code that is meant to be used by others, it's not very good code. As I explained it does not check that things that can go wrong don't go wrong. With file I/O things often go wrong. If you can't modify the code and the author can't improve it, then don't use it.
Huadong Hu
on 16 Sep 2019
Guillaume
on 16 Sep 2019
No, the version of matlab does not matter.
So, do the files exist or not?
If the files don't exist then you need to figure out why not. Most likely it would be because lfpsplitter had a problem (again, the code doesn't check for that!). Was there anything displayed on the command line?
Maybe change the line:
system(sys_command,'-echo');
to
status = system(sys_command,'-echo');
assert(status == 0, 'lfpsplitter returned an error status');
Bjorn Gustavsson
on 16 Sep 2019
...another suggestion is that you temporarily remove all semicolons in the function - this should have the consequence that all return-values will be displayed in the command-line and you can inspect them one by one and see what's happening. This is a nuicance when running code, but can give information during debugging.
Huadong Hu
on 16 Sep 2019
Edited: Guillaume
on 16 Sep 2019
Guillaume
on 16 Sep 2019
Of course, your second command which doesn't call lfpsplitter is not going to generate the required files, so when you try to read the inexistant files you get an error.
Clearly, from the error message in your first command, you're missing the lfpsplitter program, or it's not in the correct folder (Did I mention that the program doesn't check that things are as it expect,,,).
In the same folder with the file you want to convert, you must have a subfolder called lfptools. Within that folder, there must be an executable called lfpsplitter.exe (or lfpsplitter.bat or lfpsplitter.com)
Huadong Hu
on 17 Sep 2019
Guillaume
on 17 Sep 2019
Looks like you have the source code for that tool but you haven't compiled it, so of course you can't use it yet.
You'll have to find a compiled version of the tool or compile it yourself. The instructions for compiling it should be in the readme that came with it. Note that this has nothing to do with matlab so if you need help with that you'd be better off finding a support for that tool.
Walter Roberson
on 16 Sep 2019
1 vote
You are trying to run Linux code on ms windows. You will need to change the / in the system() command to \
4 Comments
Huadong Hu
on 16 Sep 2019
Bjorn Gustavsson
on 16 Sep 2019
So you get a valid file-ID for meta just before the loop?
Huadong Hu
on 16 Sep 2019
Bjorn Gustavsson
on 16 Sep 2019
This should work - is something I ususally find to be a very optimistic aproach to my programming, see Guillaume's answer for detailed description of what to look for.
Categories
Find more on Historical Contests 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!