Announcement

Collapse
No announcement yet.

MATLAB using Excel workbooks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MATLAB using Excel workbooks

    I have data saved on 40 separate worksheets within one Excel workbook. I am trying to write a loop in MATLAB to import, run through data from each sheet separately then export it separately as well. I am having difficulty with the import and export.

  • #2
    Re: MATLAB using Excel workbooks

    Your post is short on details, but the three commands you need are:
    xlsfinfo -- the second output gives you a list of the spreadsheets in the file
    xlsread -- reads the specified spreadsheet.
    xlswrite -- writes the specified matrix/cell array to a worksheet in the file

    Once you have the list of spreadsheets, you can loop through them while you read/analyze/write the data. I would recommend writing to a new file, so your input data remain unaltered (just in case of errors).

    Comment


    • #3
      Re: MATLAB using Excel workbooks

      Hello

      A good trick to learn about the coding required (or to generate it) is to use the GUI approach to importing a worksheet, and then to select "generate script" on the options. This will then generate the script required to import the Excel worksheet following the settings you set. Either re-use this, or learn from it to understand what is required to for you....sometimes I find the generated scripts to not be the most concise due to them including a lot of default commands.

      Comment


      • #4
        Re: MATLAB using Excel workbooks

        I often use the function 'dir' to import multiple files.
        Basically,
        d = dir('*.txt'); %use can change file extension and * is a wild card that populates all files fitting the string.
        then, use a loop to load variables
        for i =1:length(d)
        fname = d(i).name;
        data = load(name);
        % other code
        end

        I also like the comment on using a GUI. Might try that soon.

        Comment

        Working...
        X