In reply to itsThere:
The suggestion of running it without the loops is a good one. Another trick is to add
display(path1) right after
path1 is assigned, and leave the loop in. That will tell you which TIFF file it is trying to process when it errors.
> "path1 = [basePath, tifFiles(k).name]; "
> k is a number and the file name will be a char or a sting(I dont know), bad things will happen anyway. Could be same error as below, why not write it all into one line.
This is a bit of an oddity of MATLAB syntax, but perfectly correct.
tifFiles is an array of structures returned by
dir().
k is a number used to index into the array and pick out an individual struct, then .name takes the name field of that struct. So it returns a char array, as it should. (In MATLAB the terms "char array" and "string" are used interchangeably. There is no real string class as such, but it doesn't matter because pretty much anything you might want to do with a string you can do with an array anyway).
> but i think i may have misunderstood your code there.
> Matlab has a problem with your input to imcrop(), comment out cropPos and stick it in imcrop(image, [20 20 40 40]); matlab may be seeing it as imcrop(image, 20, 20, 40, 40); hency the varargin in the error.
MATLAB won't do this. An array is always treated as a single argument. You might be able to pass multiple args by abusing the cell class, but not an array of doubles.
> Why is path1 not a char and path2 is?
This I did not notice. The cast to char shouldn't be necessary, as MATLAB will automatically (and silently) cast something to char if it's concatenated with a char. And all of those arguments should already be chars. The cast shouldn't be harmful though.
Aside: in MATLAB, the following are all true:
'a'==char(97)
double('a')==97
'a'==97
Yes, that last one is retarded. Even more fun:
'abc'=='abc'
evaluates to
[true true true]
which is why you should always use strcmp().