Help reading an Excel file with Matlab

In summary, the conversation is about using the readtable command in Matlab to convert an Excel file into a table. The person is having trouble with the command since it is only available in the r2013b version of Matlab and they have the r2010b version. They are advised to try using the xlsread function or csvread if they do not have the Statistics Toolbox. The conversation also mentions the availability of the dataset array in the Statistics Toolbox.
  • #1
quantumspark
2
0
Hi everyone, this is my first post on the physics forums. I am trying to use the readtable command in Matlab to make a table from an Excel file. Matlab is still new to me so I'm running into problems a lot. When I input T = readtable('myfile.txt'), I get an error that says "? Undefined function or method 'readtable' for input arguments of type 'char'." Can anybody tell me what to do differently? I followed the Matlab instructions to the tee.
 
Physics news on Phys.org
  • #3
Oh, looks like I have the r2010b version. So I guess it only works in the latest version?
 
  • #4
quantumspark said:
Oh, looks like I have the r2010b version. So I guess it only works in the latest version?

if you poke around google there may be some user code to do it.

Did you try the xlsread function? it appears to be in earlier releases. Just change the name from readtable to xlsread.
 
  • #5
If you have a text file csvread will work too.
 
  • #6
Tables and categorical arrays are new for R2013b, so you won't be able to use them in older versions even if you use a legacy import function.

There is a catch though, if you have Statistics Toolbox. If so, you can use a dataset array from the toolbox (very similar to a table).
 

FAQ: Help reading an Excel file with Matlab

1. How do I import an Excel file into Matlab?

To import an Excel file into Matlab, you can use the xlsread function. This function takes in the file name as the first input and the range of cells to import as the second input. You can also use the readtable function to import the data as a table.

2. Can I specify which sheet to import from an Excel file?

Yes, you can specify which sheet to import from an Excel file by using the 'Sheet' parameter in the xlsread or readtable function. You can either specify the sheet name or the sheet index number.

3. How do I handle missing data in an Excel file?

To handle missing data in an Excel file, you can use the NaN (not a number) value. When importing the data into Matlab, you can specify which values should be considered as NaN by using the 'TreatAsEmpty' parameter in the xlsread function.

4. Can I import only specific columns from an Excel file?

Yes, you can import only specific columns from an Excel file by using the xlsread or readtable function. You can specify which columns to import by using the 'Range' parameter and specifying the range of cells or column names.

5. How do I export data from Matlab to an Excel file?

You can export data from Matlab to an Excel file by using the xlswrite function. This function takes in the file name as the first input, the data to export as the second input, and the range of cells to export as the third input. You can also use the writetable function to export data from a table to an Excel file.

Similar threads

Replies
3
Views
1K
Replies
18
Views
5K
Replies
9
Views
3K
Replies
4
Views
6K
Replies
2
Views
2K
Replies
7
Views
8K
Replies
5
Views
2K
Back
Top