Save workspace with same load file name

조회 수: 4 (최근 30일)
Setiadi Suriana
Setiadi Suriana 2020년 12월 14일
댓글: Rik 2022년 4월 29일
How to save matlab workspace automatically with same load file name? Thank you
  댓글 수: 2
Rik
Rik 2020년 12월 14일
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 2020년 12월 14일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2020년 12월 14일
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
Little Flower
Little Flower 2022년 4월 28일
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 2022년 4월 29일
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?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by