Saving matlab result in different directory

I want to save result of a function in a different directory. But the fne name needs to be changed as i am storing results for different cases in a for loop.
cas={'a','b','c','d','e','f','g'};
save(cas{dataset},'result','ORDER');
by doing this i am able to save result of different in the same directory with different names.
I would like to know if there is a way to do the same, but in a different folder.

 채택된 답변

Katie
Katie 2019년 11월 1일

1 개 추천

Hi! You can do this by using the full file path in your file name. For example:
filename=strcat('C:\Users\katie\Documents\MATLAB\',cas{dataset});%concatenate the file path with your file name
save(filename,'result','ORDER')
Above, ''C:\Users\katie\Documents\MATLAB\'' is my file path.
With strcat, you can input as many strings as you would like to be concatenated. So, if you wanted to save each result into a different folder, you could set up your filename in such a way to do it:
filename=strcat('C:\Users\katie\Documents\MATLAB\',foldername{dataset},'\',cas{dataset},'.mat');

댓글 수: 2

Farzeen
Farzeen 2019년 11월 3일
편집: Stephen23 2019년 11월 3일
Thank you Katie. it works perfectly.
Stephen23
Stephen23 2019년 11월 3일
편집: Stephen23 2019년 11월 3일
To generate filenames it is recommended to use fullfile rather than concatenating strings:
filename = fullfile('C:\Users\katie\Documents\MATLAB',cas{dataset}))

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

제품

릴리스

R2016a

질문:

2019년 11월 1일

편집:

2019년 11월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by