1

I have the following problem. I use a self organizing map to sort images (>20000) and copy the sorted ones into a new folder in the new order. It turned out that copyfile is very very slow (1 image per second) and as I found in several posts there is no solution to this. So 1. question is there a solution ? I tried an alternative and I am now just renaming the files using:

c=1;
for i = b
    file = av_files(i).name;
    in  = strcat(inputdir,'\',file);
    out  =sprintf('%s\\%0.5i_%s',inputdir,c,file);
    java.io.File(in).renameTo(java.io.File(out));
    c=c+1;
end

Now I get the error

Static method or constructor invocations cannot be indexed.

The problem seems to be that I am using it in a for loop which Matlab does not like. Is there a way around this? So the question is mainly how to rename and/or copy a large number of files in a fast way without error in Matlab.

btw movefile is comparably slow

horseshoe
  • 1,437
  • 14
  • 42
  • what is `file`, `in` and `out` when your error is thrown? you could use `dbstop if error` to check – matlabgui Jan 18 '16 at 10:04
  • file contains a list with all filenames in the folder. b contains the sorted list. In is then the inputpath and out is the outputpath with the new filename. so e.g. filename ist roi1.8499829300.tif and in would be c:\roi1.8499829300.tif out would then be c:\00001_roi1.8499829300.tif – horseshoe Jan 18 '16 at 10:12
  • the error appears directly in the first step c=1. If I copy the whole loop into the workspace (outside the m-file) it works without error – horseshoe Jan 18 '16 at 10:13
  • type `dbstop if error` before running your script and verify what the variables **actually** rather than what you think they should be. – matlabgui Jan 18 '16 at 10:15
  • actually its: c= 1, file = roi2.8523947000.tif, in=C:\train_sort\roi2.8523947000.tif and out: C:\train_sort\00001_roi2.8523947000.tif and it stops at java.io.File(in).renameTo(java.io.File(out)); – horseshoe Jan 18 '16 at 10:28
  • your approach involves loading the file and writing the file, which is always going to be slow depending on your PC specs. If you are just renaming all the files, you could do it in $Bash using `mv` http://stackoverflow.com/questions/7450818/rename-all-files-in-directory-from-filename-h-to-filename-half – GameOfThrows Jan 18 '16 at 11:01
  • @ GameIfThrows: Thx but I want to hand out the skript to other users (mainly students) not too firm with matlab and batch. So I would prefer to stick to Matlab and keep the number of different steps low. – horseshoe Jan 18 '16 at 11:11

0 Answers0