Multiple Files into Multiple Variables

4 views (last 30 days)
Pete
Pete on 8 Jul 2015
Edited: Stephen23 on 19 Jun 2019
Hi, Beginner again trying to handle files. I've got a folder with >250 files in it (csv files, 100x150 each), filled with doubles between 0 and 1. What I'm looking to do is to read each of these files into the workspace, and store as a variable with the filename as the variable - to make it easier, they have been output using Matlab, and output from a loop with:
csvwrite([num2str(FolderName) '/GL' num2str(FileNameGL) ' Amplitude'],Amplitude); % Writes the Pixel Values into CSV File
The variable FileNameGL above is grey-level values which change from 0-255, and the csv is output with this in the name.
I'd like to read this file in again, within another script, assigning it to a variable, for example, GL#_amp, where # will increment and reflect the grey-level of the filename. NOTE that the grey-levels are not related to those in the file, they are essentially just file numbers. Summary: how to set a variable in workspace as a read-in-file, then set a new variable with a new file, and repeat as many times as required... I know I could use variable as an individual cell in a variable, but is there a way to set as separate variables?
Thanks all.

Answers (2)

Steven Lord
Steven Lord on 8 Jul 2015
You can do what you are trying to do, but DON'T. Use the techniques described in question 1 in the Programming section of the FAQ instead of trying to create individual variables.

Stephen23
Stephen23 on 8 Jul 2015
Edited: Stephen23 on 19 Jun 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!