UKC

Any Matlab users here?

New Topic
This topic has been archived, and won't accept reply postings.
 crayefish 16 Jan 2014

Any proficient Matlab users out there?

I have a batch image processing program (mostly done by my friend as my Matlab skills are reasonably basic and limited to functions really) and currently it only looks for .tiff files in folders that are two tiers down from the parent folder. However I want to change it so that it will look four tiers down for image files.

I think this is the code where that needs to be changed but I can't be sure...

if bri == 1 || col == 1 || cone == 1 || pen == 1 || turb == 1 || std == 1;
imPath = char([get(handles.edit1,'String')]);
folderList = get(handles.listbox1, 'String');

len = length(folderList);
set(handles.edit4, 'String', len);

for i = 1ength(folderList);
set(handles.edit3, 'String', i);
fileList = dir(char([imPath,'',char(folderList(i)),'*.cih'])); % select folder path to search for .cih files
fileName = char([{fileList.name}]);
imFile = fileName(1:end-4); % get file name without number
TIFs = dir(char([imPath,'',char(folderList(i)),'*.tif']));
TIFNames = {TIFs.name};


I can email someone the set of Matlab files if that helps.
Post edited at 13:25
 Jack B 16 Jan 2014
In reply to crayefish:

I haven't really got time now to take a proper look but first impressions:

1) It looks like a GUI is involved, in which you select a path
2) It then looks in every subfolder of that path for *.cih files
3) For every *.cih file it finds, it strips 4 characters off the end (probably the file extension) and saves it in a variable 'imFile'
4) It then looks in the same place for *.tif files, and collects their filenames into a variable called TIFNames

The forum has eaten your whitespace and some slashes, it might be better to put chunks of code somewhere like pastebin.com, and put a link here.

What exactly do you want it to do instead?
- Do you want it to handle cih files the same as now, or change that too?
- Do you want all tif files under the starting path, or only those 4 or less folders deep, or only those exactly four folders deep?

The function 'dir()' is the one that finds files, and it doesn't have an option to search within subfolders. So you'll have to write your own, or get something from mathworks fileexchange
OP crayefish 16 Jan 2014
In reply to Jack B:

Hi Jack. Many thanks for your reply!

1. Yep you are right... the path in the GUI selects the parent folder.
2. Yeah, the .cih files (a by-product of the Photron camera software - each batch of images recorded has one) are used just to identify the base file name of the image batch.
3. Yep
4. Yep

Yeah it seems it has. I'll post a link in a minute.

I still just want it to handle the .cih files in exactly the same manner. Ideally I'd like it to find all files under the starting path but as I understand it, this is difficult. I would be ok with having it find files exactly four folders as I can just have different programs (I compile them as .exe) for different data batches depending on how the files are recorded. Generally for all my experiments they are 2 folders deep, except this one where it's four folders deep due to the number of experimental variables.

When my friend wrote the program, I asked her to set it too look two folders deep as she said she could set it to any level, as long as it was exact (she doesn't know how to do it so it searches in all folders under the parent directory). So I would assume it can be changed from 2 to 4.

Normally I'd ask her, but she is away for a week.
OP crayefish 16 Jan 2014
In reply to crayefish:

http://pastebin.com/download.php?i=1vQ3WtuD

That's the link. I have included a bit more code below just to make it a little clearer.
 Jack B 16 Jan 2014
In reply to crayefish:

Here's a function I threw together that should find all the files matching a certain pattern under a directory. I've tried to include enough comments so you can see how it works.
http://pastebin.com/EFPffvaY
Put a copy of that somewhere on your matlab path, then replace your line
TIFs = dir(char([imPath,'',char(folderList(i)),'*.tif']));
with
TIFs = dirRecurse(imPath,'*.tif',4);

If you are satisfied that your directory structure is and will always be sane, you can change the 4 to inf to search an unlimited number of levels down.

Not fully tested, YMMV, don't blame me if it explodes etc. etc.
OP crayefish 16 Jan 2014
In reply to Jack B:

Thanks very much Jack! I'll give that a go tomorrow. Most appreciated.

New Topic
This topic has been archived, and won't accept reply postings.
Loading Notifications...