MATLAB Answers

'.' is not an internal or external command, nor is it a runnable program or batch file

4 views (last 30 days)
Huadong Hu
Huadong Hu on 16 Sep 2019
Commented: Guillaume on 17 Sep 2019
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, 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')) ;
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)


Bjorn Gustavsson
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.

Sign in to comment.

Answers (2)

Guillaume on 16 Sep 2019
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.


Show 8 older comments
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
Huadong Hu
Huadong Hu on 17 Sep 2019
the Ifptools folder have files like the picture.QQ图片20190917075828.png,Is it due to the lack of the corresponding file or the code problem?
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.

Sign in to comment.

Walter Roberson
Walter Roberson on 16 Sep 2019
You are trying to run Linux code on ms windows. You will need to change the / in the system() command to \


Show 1 older comment
Bjorn Gustavsson
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.

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!

Translated by