Borrar filtros
Borrar filtros

Higher rank tensor: how to export and read it as a file?

5 visualizaciones (últimos 30 días)
Philipp
Philipp el 7 de Jun. de 2023
Comentada: Divyam el 8 de Jun. de 2023
Hello,
I have a rank-3 tensor, say simply
tensor=zeros(dA,dB,dC);
where dA, dB and dC are the respective dimensions. I like to export it as a file and later on import it again to continue some calculation in another Matlab script. How do I do this? As far as I see, dlmwrite, cswwrite and writematrix only work for matrices and give me some error saying "transpose not defined...".
Many thanks!

Respuestas (1)

Divyam
Divyam el 7 de Jun. de 2023
If you have access to the tensor toolbox, you can simply use the export_data function to export the tensor data and save it to a file. The following command should work in your case.
export_data(tensor, "tensor_data.tensor")
For more information on exporting and importing tensor data using the tensor toolbox, you can refer to this article: Importing and Exporting Tensor Data (tensortoolbox.com)
  2 comentarios
Philipp
Philipp el 7 de Jun. de 2023
Unfortunately I do not have access to the tensor toolbox as I am using Octave... :(
Anyway, I found out that I can use the reshape command as follows:
tensor_new = reshape(tensor,[dA*dB,dC])
then export tensor2 and after importing it again convert back via
tensor = reshape(tensornew,[dA,dB,dC]))
That seems to work well. :) Hopefully, I am not overseeing something...
Divyam
Divyam el 8 de Jun. de 2023
@Philipp that should work well, there shouldn't be any issues with converting a tensor to an array. I dont think that you are overseeing something just keep the dimensions in check.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Export 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!

Translated by