Hey guys,
I would like to input a string and then ask matlab to save a series of data with the file name of already input string. e.g. if the string that is input in the starting point of program is analyzed_data1 how can I assign this string in file_name below? Supposedly that there are several save commands, it would help to avoid frequently typing analysed_data1 every time.
save(fullfile(path,'file_name'));
Thank you so much :)

 채택된 답변

Titus Edelhofer
Titus Edelhofer 2011년 5월 26일

1 개 추천

Hi,
you are nearly there, I believe: suppose you write in your program at the top
myfilename = 'analysed_data1';
you just call save with
save(fullfile(path, myfilename));
Titus
PS: you might also want to take a look at uigetfile ...

댓글 수: 5

M G
M G 2011년 5월 26일
Thanks for your answer, but if you run this:
filename= input('input a file name');
path='D:\...'; %Set a path
a= [1 2 3 4 5;2 3 4 5 4];
save(fullfile(path,filename),'a');
and give a string as a name it doesn't really work!!!
Titus Edelhofer
Titus Edelhofer 2011년 5월 26일
Hi Mehdi,
strange. Works for me, when entering the filename as a string, i.e., when prompted for filename I entered 'foo' (including the two ').
Titus
Walter Roberson
Walter Roberson 2011년 5월 26일
Medhi, you need to use the 's' option on input()
filename = input('input a file name', 's');
It helps if you say specifically the problems you encounter rather than just sayiing "it doesn't really work"
Titus Edelhofer
Titus Edelhofer 2011년 5월 26일
I guess by now the question is obsolete, because Mehdi asked a somewhat similar question with topic "save path" ...
M G
M G 2011년 5월 27일
I got the problem. You're right. Thanks a lot :)

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

추가 답변 (1개)

Ivan van der Kroon
Ivan van der Kroon 2011년 5월 26일

0 개 추천

Depending on your os the slashes could be different. For instance on opensuse I have to use /
path='temp/matlab.mat';
save(path)
With \ it just makes a string and the \'s are just part of the filename. You can make sure to get the correct one by opening the folder and copying the path from there.

댓글 수: 1

M G
M G 2011년 5월 27일
Thanks Ivan, your comment helped :)

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

카테고리

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

태그

질문:

M G
2011년 5월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by