Enter the elements of matrix in a specified location of a text file
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a 10x10x10 matrix and each square contains a value between 1 and 2. What I want is, the first element of that matrix will be used in line 10, 2nd element in line 20, 3rd element in line 30,..........100th element in line 1000 of a text file. Is there any way to do that?
4 个评论
采纳的回答
Voss
2022-12-10
编辑:Voss
2022-12-10
% "data" would contain your data, but for
% demonstration, I use 1:1000 in order:
data = reshape(1:1000,[10 10 10]); % 10x10x10 array
% rearrange the elements of data as specified:
new_data = permute(data(:,:,end:-1:1),[3 1 2]);
% write to file, one element per line:
writematrix(new_data(:),'file.txt');
% check the result
type file.txt
6 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!