reading from excel by page

Hello,
I'm looking to read from 1 excel document that consists of 3 pages of information(EMG) each consisting of 19col. 44000rows
I would like to know how to manipulate cells from seperate pages as well as how to cross corolate between pages, if at all possible. (would it be easier from a text file?)
Any help would be greatly appreciated.
1st time Matlab user.

3 commentaires

KSSV
KSSV le 24 Mar 2016
Is the information in different sheets of excel?
Kris Lawson
Kris Lawson le 24 Mar 2016
yes the information is 3 sheets for pre, post, and follow up. The data on each sheet has the same number of input fields rows/col.
KSSV
KSSV le 24 Mar 2016
using xlsread you can read the sheet you want.

Connectez-vous pour commenter.

Réponses (1)

John BG
John BG le 24 Mar 2016

1 vote

Kris
the page of a Microsoft Excel workbook can be directly addressed in the command xlsread:
filename='wrkbk1.xlsx'
read_sheet = 3
read_range = 'B2:C3'
[num,txt,raw]=xlsread(filename,read_sheet,read_range)
the extracted data is in num. Once whatever data in MATLAB you can process it with any operation you want, and once ready you can store it back in same or another Excel spread sheet with command xlswrite that has format
xlswrite(file,A,write_sheet,write_range)
If you find this answer of any help solving your question, please click on the thumbs-up vote link,
thanks in advance
John

3 commentaires

Kris Lawson
Kris Lawson le 24 Mar 2016
Thanks for the response, John.
Would these two files be the same? filename=' wrkbk1.xlsx' read_sheet = 3 read_range = 'B2:C3' [num,txt,raw]=xlsread( filename,read_sheet,read_range)
And could you break this code down for me by variable: [num,txt,raw]=xlsread( filename,read_sheet,read_range)
Also after thinking this project through I think what I am looking for is a nested loop for 6 variables to process all 44001 rows of data per column. This way I can reuse the code for future projects and just replace the file names.
Six variables for individual cells:
  • P1a = Page 1 odd columns (A1-A44000, C1-C44000, E1-E44000, etc)
  • P1b = Page 1 even columns (B1-B44000, D1-D44000, F1-F44000, etc)
  • P2a = Page 2 odd columns
  • P2b = Page 2 even columns
  • P3a = Page 3 odd columns
  • P3b = Page 3 even columns
I would add a line of "0" at the end of each column as to establish an internal reset:
  • filename='wrkbk1.xlsx'read_sheet = 1read = 'A1'*
Start Loop
If P1a~= 0
xlsread
  • filename='wrkbk1.xlsx'read_sheet = 1read = 'A1'* (=P1a need code to +1 down the coulmn each loop pass)
*filename='wrkbk1.xlsx' read_sheet = 2 read = 'A1' (=P2a)
do my calculations
Then I use the xlswrite function you mentioned.
xlswrite (Results,A)
I am probably missing a nested loop here to continue calculating without constantly overwritting Cell A1 with the results
If P1a = 0
  • filename='wrkbk1.xlsx'read_sheet = 1read = 'A1'* (Pa1= need code to move +2 coulmn & reset cell to 1)
Else Restart Loop
END Loop
Again, I might be biting off more then I can chew with this program at the moment, but any help with this type of code would be greatly appreciated.
Thank You again, John, for your quick reply.
John BG
John BG le 26 Mar 2016
for instance, there is an excel file called ShipData.xlsx that looks like this:
When reading with
[num,txt,raw]=xlsread('ShipData.xlsx','ShipData','A1:B10')
you get the following
num =
9180401.00
9376036.00
9354868.00
9573000.00
9179397.00
9293545.00
9707792.00
8972194.00
9148142.00
txt =
'Register Number' 'IMO Number'
'12536D' ''
'14968W' ''
'16283B' ''
'15126T' ''
'06466F' ''
'04893V' ''
'22394T' ''
'962G60' ''
'39Y697' ''
raw =
'Register Number' 'IMO Number'
'12536D' [9180401.00]
'14968W' [9376036.00]
'16283B' [9354868.00]
'15126T' [9573000.00]
'06466F' [9179397.00]
'04893V' [9293545.00]
'22394T' [9707792.00]
'962G60' [8972194.00]
'39Y697' [9148142.00]
the file name can be the same or a different file, it's up to you.
Hope it helps.
Regarding your design reasoning, i rather not go through it until you have a script that, working or crashing, is a concise start point for another question or comment.
John
Kris Lawson
Kris Lawson le 26 Mar 2016
Ok. Thank you very much for clearing that up for me.
I will post again when I have some code underway.

Connectez-vous pour commenter.

Catégories

Commenté :

le 26 Mar 2016

Community Treasure Hunt

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

Start Hunting!

Translated by