Enter the elements of matrix in a specified location of a text file
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Voss
le 10 Déc 2022
Modifié(e) : Voss
le 10 Déc 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!