Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Creating new variable name matrix in loop
Replies: 3   Last Post: Jul 28, 2014 11:04 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Callum Black

Posts: 4
Registered: 3/24/14
Creating new variable name matrix in loop
Posted: Jul 28, 2014 8:16 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi, I have read a few topics that discussed saving new variable names in loops, however i could not find any that resolved my problem.

I am trying to import '.txt' files, a matrix with approx 16 columns. Each time i import them, i want to name each new matrix with a new name, I.e. T1, T2, T3 etc. I can do it manually, however this is time consuming and i have many files in different folders that i will wish to import.

My script follows:

fpath=uigetdir; % user selected path to directory
files=dir([fpath '\*.txt']); % open directory, list files ending txt
files=char(files.name); % list of file names

m=1:length(files);
for i=1:length (m);
% Importing data files
T_1=importdata([files((1),:)]);

for x=1:length(files); %($$$$$$$$$$$$)
T(x)=T_1.data;
end
end

I know that where the line i have marked as '($$$$$$$$)', is wrong, but i am struggling to change the name. Ideally, i would like to name the matrix with a reference to the file name, but i am not too worried about that at the moment.




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.