1

I have several nested loops that allow me to build a matrix of 21 row by 20000 columns.

Each column of the array above has a string associated which I store in a variable called filename at each loop iteration (the string gets replaced at each iteration).

Is there any what to create a vector (1-by-20000) with the strings so that I can then export to Excel?

clear all

n = 201;


PP=[];
pathname = 'D:\';
addpath(pathname);

for Y = 1:20           
 for B = 1:2          
  for z = 1:50;          
   for R = 1:2;     
    for I = 1:5;

     filename = strcat('F', num2str(Y),'_',num2str(B),'_',num2str(z),'_',num2str(R),'_',num2str(I),'_',num2str(C),'.txt');

     aux = load(filename); 
     PP = [PP aux(1:n)];

   end
  end
 end 
end

rmpath(pathname)
0

1 Answer 1

2

Have you tried using cell arrays:

filenames = {}; %// Before your loops

filenames(end+1) = {filename}; %// Inside your loops
Sign up to request clarification or add additional context in comments.

3 Comments

That works. Thanks. The only thing I am missing is how to export the strings to excel. One name per string.
And you have tried the xlswrite function?
I tried and it was not working. But it was another issue. Now it is ok.Thank you very much. I will accept your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.