Friday, September 7, 2012

batch processing multiple files in matlab using for loop and uigetfile function

Recently I got a bunch of files that have the same format and structure and I need to use Matlab to process each file, which means carrying out the same calculation procedure to each file. Here's the code I created to do this.

% Import the file names
% The {*.csv} parameter indicates that only csv files will be shown in the file selection window
% Turn on the MultiSelect parameter so that multiple files can be selected at the same time
[filename, ~,~]=uigetfile({*.csv}, 'MultiSelect', 'on');
% now use a for loop to carry out same calculation procedure to each file
% the process_each_file is a function that does the calculation procedure
% before using the for loop, let's define a space to store all the outputs from each file calculation first
Re=zeros(length(filename),1);
for i = 1 : length(filename)
     Re(i)=process_each_file ( filename(i))
end




3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. hello!
    First of all I would like to thank you and say congratulations because your blog is awesome and has help me so much.

    I am a student dealing with MatLab and want to do something like you are doing in this article.
    Hope you can help because I think I must be mistaken in something without importance but I can not overcome this step and is really pissing me off!

    Let me explain you:
    I have created a GUI with a first button with the uigetfile to get DICOM files; in order to make a handle I can work with in other buttons.

    I have tried the commands you put here and in the process_each_file function make a dicomread and a handle, but it gives me error "too many output arguments".
    If I write the function like this:
    function [Fname] = process_each_file(Fname)

    I get:
    The following error occurred converting from cell to double:
    Error using double
    Conversion to double from cell is not possible.


    Hope you could help me; what I'm trying to do is get more than one dicom file with uiget and multiselect on, then use dicomread and make handles to use in other buttons.

    Thank you so much for your time and work these years, your trick and tutorials are just great, we talk to them a lot in the university.

    Best regards,
    José Luis

    ReplyDelete
    Replies
    1. Hi Jose,
      I don't totally get your questions, but here are my 2 cents about the error message you got.

      For the first one, 'too many output arguments' is a pretty straightforward one. You just used too many output arguments. You can define more output in the function to fix this issue.

      For the second one, you need to look into the matlab data type and how to convert them. This link should be helpful:
      http://www.mathworks.com/help/matlab/data-type-conversion.html
      Good luck!

      Delete

Any comments?

my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...