MATLAB: Import an Excel File

excelimport data

Hi,
I have given an Excel table. This Excel table I have imported with "Import Data" and saved as a cell array as "generate function". Now I want to asign the content of the imported file to a variable. Can I do that with: imp = importfile_1(file path of the created import file);
The problem is that it doesn't work atm. The entries in the variable are not equal to the excel entries.
At the end I want to have a two dimensional array with the entries of the Excel file.
I hope one of you can help me.

Best Answer

I think that I am starting to see what you did, and it is not something that we generally do actually, hence the misunderstanding.
Using the Import Data tool (and not the function), you loaded the content of an Excel workbook. Then you asked the tool to generate a function for you. Now the tool doesn't generate a function with the data. It generates a function for loading the data from the same Excel file that you initially opened, to allow you to bypass this step the next time that you want to read the data. What this function takes as an argument is the path/name of the original Excel file. So if you opened file MyData.xlsx with the Import Data tool, the correct call for loading the data from the same file is
data = importfile( 'MyData.xlsx' ) ;
or
data = importfile( 'C:\ ... whatever path ..\MyData.xlsx' ) ;
Now we never do all this with the import data tool. Instead we call directly the XLSREAD function (you can check that the importfile script does that too):
[~, data] = xlsread( 'MyData.xlsx' ) ;
where the first output of XLSREAD is a numeric array that we discard with ~ because you have no numeric data in your workbook, and the second contains the text.
If you don't want to read the original Excel file next time (because it is slow), you can now save the cell array data into a MAT-File using SAVE, and load it using LOAD (you'll have to read the doc to see how it works).
Apparently, you want to split each line into words, which you can do with STRSPLIT. You can try on the content of the first cell of data:
strsplit( data{1}, ' ' )
and see that you have a cell array of words. Then you can think about implementing e.g. a loop over all cells of data and store the words in another cell array for example.