Convert cell to string, or assign variable

18 vues (au cours des 30 derniers jours)
J
J le 25 Avr 2012
Commenté : zeeshan yousaf le 8 Juin 2016
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)
  1 commentaire
zeeshan yousaf
zeeshan yousaf le 8 Juin 2016
Use strjoin as: str=strjoin(cells);

Connectez-vous pour commenter.

Réponses (2)

Evan
Evan le 25 Avr 2012
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 commentaire
Bo Landess
Bo Landess le 21 Nov 2012
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).

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 25 Avr 2012
YourVariable = TheCellName{1};
YourOtherVariable = 'C:\MyFiles\MATLAB\project17\avioQ38.jpg';

Community Treasure Hunt

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

Start Hunting!

Translated by