필터 지우기
필터 지우기

How can I save a filename as a string, not as a char?

조회 수: 3 (최근 30일)
matlabq123
matlabq123 2018년 9월 6일
댓글: Walter Roberson 2018년 9월 6일
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

답변 (1개)

Alexander Jensen
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
matlabq123
matlabq123 2018년 9월 6일
This shows up for "which -all string": "built-in (undocumented)"
I am using R2013B.
Walter Roberson
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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by