Reading a excel spread sheet

I am new to MATLAB. I want the script that creates a loop to read columns of spread sheet. For example read column A and B, then column A and C, then column A and D.
Then is it possible for the script to name and save files according to dimensions specified in the spreadsheet?

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 27 Dez. 2012
Bearbeitet: Azzi Abdelmalek am 27 Dez. 2012

0 Stimmen

Use xlsread function to read excel files, to name files according to a number k, use sprintf command
k=2
filename=sprintf('fil%d',k)
Image Analyst
Image Analyst am 27 Dez. 2012

0 Stimmen

It's best not to read columns in a loop. It's better to just read the whole worksheet into MATLAB all in one call to xlsread because each time you call xlsread it has to launch Excel get the numbers out, and then shut down Excel, which can take a long time if you have to do it more than twice or so. If you really want to do it that way, then it's best if you just open it once with ActiveX, then you can read as many things as you want in individual calls very quickly, and then shut down Excel once after you're done with all your reads. To create cell references for doing that, you use sprintf():
cellReference = sprintf('A%d:D%d', startingRow, endingRow);
You can search this forum for ActiveX demos for Excel - I know I've posted them, and other have too.
Creating filenames also uses sprintf as Azzi showed you, and the FAQ has example code for.

Tags

Gefragt:

am 27 Dez. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by