Save workspace with same load file name

How to save matlab workspace automatically with same load file name? Thank you

2 comentarios

Rik
Rik el 14 de Dic. de 2020
As far as I understand your question I don't see why you would want to do that.
Can you explain in a bit more detail what you mean and what you want? Have a read here and here. It will greatly improve your chances of getting an answer.
Setiadi Suriana
Setiadi Suriana el 14 de Dic. de 2020
For example, I load data from file name a.txt, therefore i want to save output from workspace with name a.mat. How to do it automatically if I have a lot files?

Iniciar sesión para comentar.

 Respuesta aceptada

Rik
Rik el 14 de Dic. de 2020
You can use code like this in a loop.
file_name_including_dot_txt='example.txt';
data=function_that_reads_your_file(file_name_including_dot_txt);
[p,fn]=fileparts(file_name_including_dot_txt);
matfilename=fullfile(p,[fn '.mat']);
save(matfilename,'data')

2 comentarios

Little Flower
Little Flower el 28 de Abr. de 2022
Hello Rik, if I want to save it in a folder how can i change the last line of your code? kindly clarify
Rik
Rik el 29 de Abr. de 2022
Edit the second to last line. That is where the location and file name is determined. What exactly do you mean by saving in a folder?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Productos

Versión

R2017b

Etiquetas

Preguntada:

el 14 de Dic. de 2020

Comentada:

Rik
el 29 de Abr. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by