Enter the elements of matrix in a specified location of a text file
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 10 Dec 2022
Edited: Voss
on 10 Dec 2022
% "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 Comments
More Answers (0)
See Also
Categories
Find more on Cell Arrays 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!