Enter the elements of matrix in a specified location of a text file
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MD MAHABUBUR ROHOMAN
am 10 Dez. 2022
Kommentiert: Voss
am 12 Dez. 2022
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 Kommentare
Akzeptierte Antwort
Voss
am 10 Dez. 2022
Bearbeitet: Voss
am 10 Dez. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!