Enter the elements of matrix in a specified location of a text file
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MD MAHABUBUR ROHOMAN
el 10 de Dic. de 2022
Comentada: Voss
el 12 de Dic. de 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 comentarios
Respuesta aceptada
Voss
el 10 de Dic. de 2022
Editada: Voss
el 10 de Dic. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!