0

I load my .txt files from a directory, in which contain 4x4 matrices, directly in a variable (rotLM) with following code in octave:

  for i= 1:5
    file_rotLM= strcat('C:\Users\pc\Desktop\matrices\rotLM',int2str  (i),'.txt'); 
    rotLM= strcat('rotLM',int2str(i))
    rotLM= load(file_rotLM);
  end

What I want: the variable name "rotLM" should contain the concatenated string at the end. Like: "rotLM1, rotLM2...rotLM5" and each those variables should contain the corresponding matrix paramters. If I run above code I get only :

 rotLM = rotLM1
 rotLM = rotLM2
 rotLM = rotLM3
 rotLM = rotLM4
 rotLM = rotLM5

And if I tip in command window: rotLM it gives me only the last read matrix, but if I enter e.g. rotLM1 I get error "'rotLM1' undefined near line 1 column 1"

What is my mistake here? Thank you!

0

1 Answer 1

1

NEVER put indices into your variable name, assuming you get it done in the first place you end up with code which is horrific to maintain. There is for example no iterator for such variables. Instead use a cell array:

n=5
rotLM=cell(n,1);  
for ix= 1:5
    file_rotLM= strcat('C:\Users\pc\Desktop\matrices\rotLM',int2str(ix),'.txt'); 
    rotLM{ix}= load(file_rotLM);
end
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.