Generating Randomization from a text file
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a text file contains numbers like the following :
1 2 3
7 5 6
4 5 5
9 11 1
I want to redistribute the lines randomly to be for example like this:
7 5 6
9 11 1
4 5 5
1 2 3
I know about the function " randperm " but I want to use it in case I have a text file and I want to generate the randomization inside it.
Regards,
1 个评论
Jan
2019-9-4
What is your question? Do you know how to import the data from a file to a matrix? Do you know how to shuffle the rows? Does the problem include how to write a matrix to a text file? What have you tried so far?
采纳的回答
Sai Sri Pathuri
2019-9-4
You can read the matrix from the text file, randomize the rows and rewrite it to the text file.
a=readmatrix('filename.txt');
To shuffle the rows, you may use the following code.
b=a(randperm(size(a,1)),:);
writematrix(b,'filename.txt','Delimiter','tab');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!