MATLAB: Readtable then save in workspace with a new name based on a variable

rename table based on variable

I have a large number of excel spreadsheets and want to extract data for comparisons and graphs. I don't want to generate more saved files, but I do want to load the information from each file into the workspace for manipulation. I'm getting each set of data using a loop. Once I have it, I need to rename the table so that when I loop around for the next set of data it isn't overwritten. I'd like to use a name from a list of identifiers (RodList) which I've moved to a string as "rodname". I'm sure there is a simple way to do this…I'm a newbie…any help would be much appreciated!
for next = 0:0
nextfile = RodList(next + 1); % index to next rod in the list
sourcedir = 'C:\Users\rnm\Scans\';
sourceext = '.xlsx';
rodname = strcat(nextfile)
Filetoprocess = strcat(sourcedir,nextfile,sourceext);
FileData0deg = readtable(Filetoprocess{:},'Sheet','Sheet1','Range','D1:E5000');
FileData0deg = rmmissing(FileData0deg);
_ _I need to keep FileData0deg in the workspace as rodname_FileData0deg__
end

Best Answer

Use a cell array that is the size of the number of files and then read into it.
files = dir(*.xlsx');
filedata = cell(numel(files), 1)
for ii = 1:numel(files)
filedata{ii} = readtable(files(ii).name, ETC.)
end
Something along these lines. Now the fifth element in the cell is the content of the fifth Excel sheet.
Related Question