- Clearing variables on each loop iteration serves no purpose.
- Using numel rather than length is a good habit to learn.
- It is easy and advisable to check if fopen succeeded.
- textscan returns a cell array of the columns, so why not just use cell2table to get a table?
- Why not just use readtable to import the file directly into a table?
- Dynamically accessing variable names, as you are requesting is not recommended- It is much simpler and more efficient to use a cell array and indexing. Read this to know more: