Convert cell to string, or assign variable

조회 수: 25 (최근 30일)
J
J 2012년 4월 25일
댓글: zeeshan yousaf 2016년 6월 8일
How do I convert a cell into a string?
Or, how do I assign a file name to a variable, but keep it a string?
I have tried this, but it changed all the dots (.) into '0x2E' and still put it into a cell in the Workspace:
varname = genvarname(str)

답변 (2개)

Evan
Evan 2012년 4월 25일
Are you using a function like uigetfile to get the name of the file? If so, specify two outputs from it to get both the file name and the path. Then use fullfile to combine the two.
help fullfile
It would look something like this
[ filename pathname ] = uigetfile;
file = fullfile( pathname , filename );
"file" will be a string that is the full path + file name of your selected file.
Also, if a string is located in a cell, you just need to access the content of that cell.
YourCell = {'test'};
string = YourCell{1};
  댓글 수: 1
Bo Landess
Bo Landess 2012년 11월 21일
YourCell = {'test'};
string = YourCell{1};
worked perfectly... just need to pay attention to the curly brackets for the variable "string" to be returned as a string. Otherwise, it was returned as a cell (which sprint() does not work on).

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


Walter Roberson
Walter Roberson 2012년 4월 25일
YourVariable = TheCellName{1};
YourOtherVariable = 'C:\MyFiles\MATLAB\project17\avioQ38.jpg';

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by