Saving the output of a loop into a matrix or a vector

1 view (last 30 days)
Hello,
How can we save the output of a loop when it is a series of matrices
Thank you,

Accepted Answer

Stephen23
Stephen23 on 25 Apr 2015
Edited: Stephen23 on 19 Jun 2019
  2 Comments
Sha
Sha on 26 Apr 2015
Thank you very much for your detailed reply. I am trying to go through the links to get a better understanding of the problem.
"if you continue to include data in the variable names then you will find yourself fighting many more of these battles against MATLAB"
For example I can start using " X = sym('X',[3 8])" which gives me my 24 variables in a matrix, but then what I would like to do is make "column" 1 or index "1" correspond to state "HHH" then column 2 "LHH" (I permute the 2 letters in sequences of "3" so I get 8 possibilities). Is there an easy way to do that ?
Thank you very much
Stephen23
Stephen23 on 26 Apr 2015
Edited: Stephen23 on 3 Jun 2015
Sorry, I do not use sym, so I have no advice on that. Mixing data (your "states") and the variables' names is what is not recommended, as should be clear from those links.
  • You could create a separate (cell?) array to store those states and whose columns correspond to the columns of the data matrix. This would be a typical and easy MATLAB solution.
  • You might find that using a table suits your needs better than a simple matrix.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!