Selecting Specific Tab in spreadsheet

29 Ansichten (letzte 30 Tage)
CHRIS HARRISON
CHRIS HARRISON am 5 Mär. 2021
Hi (I am fairly new to MATLAB so apologies for any ignorance in the below):
I am trying to import a datasheet with multiple tabs which is outputted as a results file by a separate piece of software. The number of tabs is likely to be different each time I import this. I am interested in only a few 'types' of the tabs in this spreadsheet and these always end in "_Main" (the tabs not of interest do not end in "_Main". Ultimatey I want a script that can import these spreadsheets, identify the tabs of interest and then add a couple of columns (multiply a couple of the other existing columns), with which I am hoping to create some graphs from.
So far I have been able to bring in the data using the following:
mydata = importdata('Test1.xlsx');
When I open the data in the workspace, the data has several subheadings (data, textdata, colheaders). Within the 'data' section of this, I can see the various tabs from my spreadsheet (some with "_Main" in the title and some without). Then I have identified the tabs of interest and output them in a separate array called "g". I have done this via the following:
for i=1:numel(fnames)
if contains(fnames(i), "Main")
bingo(i) = 1 ;
else bingo(i) = 0 ;
end
end
Target=find(bingo) ;
for counter2=1:numel(Target)
TempValue1 = Target(1,counter2)
g(TempValue1,1)= fnames(TempValue1,1)
end
However, my problem is now that I am not sure how I can call up those identified tabs. I can call this up from the command window as:
mydata.data.EXAMPLE_Main
But is there a way I can codify this? e.g can I call up mydata.data.<the 2nd tab> ?
Thanks,
Chris

Antworten (1)

Shiva Kalyan Diwakaruni
Shiva Kalyan Diwakaruni am 8 Mär. 2021
Hi,
You can try using sheetnames or xlsfinfo function instead of importdata for reading data out of different tabs.
Template code to read multiple sheets with xlsfinfo would be something like below
[~,SheetNames] = xlsfinfo(filename);
nSheets = length(SheetNames);
for ii=1:nSheets
Name=SheetNames{ii};
sheetData=xlsread(filename,Name);
end
You can refer to the below links for documentation about xlsfinfo and sheetnames
you can also refer the below link for reference
hope it helps,
Thanks.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by