I keep running into an error when I try to run this code..but I am unsure why.
I am trying to import files within a for loop for each baseball team.
I think the problem is I am not setting my variable correctly..but I am totally confused as to how/what is what wrong with this code. Help most appreciated!
Most of this code was auto generated after manually importing a file.
I am getting my error at the line:
??? Error using ==> xlsread at 122 Filename must be a string.
Error in ==> importhome at 10 [numbers, strings, raw] = xlsread(fileToRead1, sheetName);
Error in ==> baseball2 at 10 importhome(fileToRead1)
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'};
folder = '';
fileToRead1 = [Str '.xls'];
importhome(fileToRead1)
sheetName='Sheet1';
[numbers, strings, raw] = xlsread(fileToRead1, sheetName);
if ~isempty(numbers)
newData1.data = numbers;
end
if ~isempty(strings) && ~isempty(numbers)
[strRows, strCols] = size(strings);
[numRows, numCols] = size(numbers);
likelyRow = size(raw,1) - numRows;
if strCols == numCols && likelyRow > 0 && strRows >= likelyRow
newData1.colheaders = strings(likelyRow, :);
end
end
for i = 1:size(newData1.colheaders, 2)
assignin('base', genvarname(newData1.colheaders{i}), newData1.data(:,i));
end