How can I save a filename as a string, not as a char?
3 次查看(过去 30 天)
显示 更早的评论
In my code, the user selects a file. That file name is assigned to "File1" as a char. Is there any way I can assign it as a string variable? I need to manipulate the name of the file after and need it in string form. Thanks.
if true
[File1,path] = uigetfile('*.txt');
if isequal(File1,0)
disp('User selected Cancel');
else
disp(['User selected ', fullfile(path,File1)]);
end
end
0 个评论
回答(1 个)
Alexander Jensen
2018-9-6
Is this what you're looking for? Or am I misunderstanding your question. And why do you need it as a string to manipulate it?
if true
[File1,path] = uigetfile('*.txt');
File1 = string(File1);
if isequal(File1,0)
disp('User selected Cancel');
else
disp(['User selected ', fullfile(path,File1)]);
end
end
5 个评论
Walter Roberson
2018-9-6
The string data type was introduced in R2016b. https://www.mathworks.com/help/matlab/ref/string.html
You will find that you do not have erase() or related functions.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!