Thanks for any assistance in advance! I have the following problem: I have generated spreadsheets of data (.xls file for each baseball team).
I want to import one xls file, do some calculations, and then move on to the next team's xls file…so on and so on..
However, the way I designed my for loop, a window pops up where I have to manually select each individual .xls file I wish to be imported.
I would like to know: how can i automate this process? What code do I need so that the program itself will know exactly which xls file to import within the for loop without me needed to manually select it each time?.
Here is my code:
for Str = {'Diamondbacks' 'Braves' 'Orioles' 'Boston' 'Cubs' 'WhiteSox' 'Reds' 'Indians' 'Rockies' 'Tigers' 'Astros' 'Royals' 'Angels' 'Dodgers' 'Marlins' 'Brewers' 'Twins' 'Mets' 'Yankees' 'Athletics' 'Phillies' 'Pirates' 'Padres' 'Giants' 'Mariners' 'Cardinals' 'Rays' 'Rangers' 'BlueJays' 'Nationals'};[fileToRead1, folder] = uigetfile();AngelsData.xls = fullfile(folder, fileToRead1);% Call the first function.
importhome(AngelsData.xls)%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Auto-generated by MATLAB on 05-May-2012 23:12:52
% Import the file
sheetName='Sheet1';[numbers, strings, raw] = xlsread(fileToRead1, sheetName);if ~isempty(numbers) newData1.data = numbers;endif ~isempty(strings) && ~isempty(numbers) [strRows, strCols] = size(strings); [numRows, numCols] = size(numbers); likelyRow = size(raw,1) - numRows; % Break the data up into a new structure with one field per column.
if strCols == numCols && likelyRow > 0 && strRows >= likelyRow newData1.colheaders = strings(likelyRow, :); endend
Best Answer