MATLAB: Loading text files using variable names

loadvariables

Hi, Is there any way of loading a text file (say mydata.txt) using a variable name? What I need to do is allow the user to input the name of a text file, which contains an array, in the previous command, and then for the program to load the file with name and store it into another variable. Thanks in advance.

Best Answer

filename = input('Enter the file name (without the txt extension)','s');
fid = fopen([filename '.txt']);
C = textscan(fid, <format to be used>);
fclose(fid);
HTH,
Arnaud