Add rows to txt file in order to create a matrix
Show older comments
Hello,
I implemented a code in matlab that gives me all the possible permutations of a 10-element vector with some peculiar features (all elements must be between 0 and 1 and the sum of all elements equal to 1).
I would like to export each permutation (1x10 matrix) I obtained to a txt file, in order to create a big matrix (# of permutations x 10) with all these permutations. The process should be: obtain the first permutation from my code, export this permutation (1x10 matrix) to the txt file as a new row, do it again for the next permutation I obtain and so on, save the matrix of all the permutations and use it again in matlab for other purposes.
Could someone help me with this issue?
If possible, I need an efficient way to do this since I have many permutations to export to the txt file. I do not know the total # of permutations.
Thank you.
Claudio
Accepted Answer
More Answers (1)
Shashank Prasanna
on 31 Jan 2013
You can keep this in a loop and use it as many times:
dlmwrite('test.txt', rand(1,10), '-append','delimiter',' ')
rand(1,10) if you permutations each time.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!