How to import and export data through MATLAB?

Hello everyone,
Thank you in advance for your help. Normally I don't like to ask without providing what I've tried, but I'm trying to save time on what I'm trying to do.
What I am trying to achieve is a script that can automate the process of importing excel data into Matlab and then exporting it into an Access database. Basically a spreadsheet with some data and then storing it into Access by adding said spreadsheet as a new table in said database. My only real problem is that I'm not sure on the specific Matlab functions the import and export data.
I've read about several different ways to import data, but none of them I have come across give me specific functions to string together, instead it they refer to the buttons available in Matlab's "Home" tab.
Any ideas or hints in order for me to do this correctly with ease?
If I didn't provide enough of an explanation please let me know. I greatly appreciate any tips/advice you all have to offer.
EDIT: Also, I'm not just going to sit and wait for an answer, I'll be trying to string something together and then hopefully, with your inputs, I can compare to what I've done and share it with what anyone has recommended. Thank you.
Thank you,
L

1 Comment

UPDATE: Still need help. First answer didn't really help.
Here is what I've got so far:
[data pathname] = uigetfile( ...
{'*.m;*.xls;*.xlt;*.xlm;*.xlsx*.fig;*.mat;*.mdl', 'Files (*.m, *.fig, *.mat, *.mdl)'; ...
'*.*', 'All Files (*.*)'}, ... 'Pick a file','C:\Users\');
stuff = importdata([pathname data]);
Previously I had xlsread instead of import data, but it wasn't grabbing the variable names (like row one has all the different names of the data, Day 1, Day 2 ,etc.). Also, the first column, column A, doesn't get pulled either (it is also full of text, John Smith, Alice Jane, etc.)
I switched to using the importdata function and that seems to work but it's output, "stuff" is a structure with two things inside. What I want is stuff to equal the data in the excel file I'm trying to pull (stuff equals the table of data, column names and row names AND data all in one).
Thank you,
L

Sign in to comment.

 Accepted Answer

KSSV
KSSV on 23 Nov 2016
Check xlsread, xlswrite.
Also go through readtable and writetable.

7 Comments

So I tried this:
data = uigetfile( ...
{'*.m;*.xls;*.xlt;*.xlm;*.xlsx*.fig;*.mat;*.mdl', 'Files (*.m, *.fig, *.mat, *.mdl)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick a file','C:\Users\');
xlsread(data);
and it is not working. I keep getting this error:
Error using xlsread (line 132)
XLSREAD unable to open file 'Test1.xls'.
File 'C:\Users\Documents\Matlab Scripts\Test1.xls' not found.
Error in Database_Script (line 9)
xlsread(data);
I know it is something with the directory, but I am trying to make a script that let's the user select different excel files that may exist in different directories. I believe the conflict is because the excel file isn't in the same spot as the script itself. How do I get around that?
Thank you,
L
[filename, filepath] = uigetfile( ...
{'*.m;*.xls;*.xlt;*.xlm;*.xlsx*.fig;*.mat;*.mdl', 'Files (*.m, *.fig, *.mat, *.mdl)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick a file','C:\Users\');
xlsread( fullfile(filepath, filename) );
So I figured that much out (see above comment on my OP), also it seems to do the same thing if i just put xlsread([pathname file]). Either way I'm still having a slight problem. When the data is read in, the text in the first row with variable names as well as the first column with names are missing from the data set. How do I fix that?
I've been tinkering with some sort of A:i thing, but I'm not sure how to get that syntax right. I appreciate your help thus far Walter!
-L
[num, txt, raw] = xlsread( fullfile(filepath, filename) );
num will always be only the numeric values. txt will be a cell array of strings in which all values that can be converted to numeric have been removed. raw will be everything in context.
You're awesome, thank you Walter! The "raw" part was what I wanted, at least I think. Then next step of my little goal is to then transfer the information contained in "raw" into a Microsoft Access database. I'm thinking I should be able to use some function with raw being used in it to save the data to a database. Got any pointers for that direction?
Again, thank you very much!
-L
Sorry, I have not worked with Microsoft Access.

Sign in to comment.

More Answers (0)

Products

Asked:

L
L
on 22 Nov 2016

Commented:

on 27 Nov 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!