Effacer les filtres
Effacer les filtres

Create a vector of strings

3 vues (au cours des 30 derniers jours)
William le 6 Sep 2012
I need to convert a vector of doubles 64x1 to strings by converting them to hex values. I tried allocating a cell
x = cell(64,1)
for hh = 1:64
hex_results(hh,:) = dec2hex(results(hh,:));
but the error....
??? Conversion to cell from char is not possible.
keeps popping up. Is there a better way to do this?
  1 commentaire
Jan le 6 Sep 2012
Modifié(e) : Jan le 6 Sep 2012
The allocated cell "x" does not appear again...
What is type and size is "results"?

Connectez-vous pour commenter.

Réponse acceptée

Jan le 6 Sep 2012
Modifié(e) : Jan le 6 Sep 2012
x = cell(64, 1);
for hh = 1:64
hex_results{hh} = dec2hex(results(hh,:)); % curly braces!
If results is a vector, try this:
Str = sprintf('%x*', results);
CStr = regexp(Str, '*', 'split');
Another idea is to use dex2hex vectorized:
Str = dec2hex(results);
But as far as I remember, this is not documented. If it is, perhaps cellstr() is required to convert the CHAR-matrix.

Plus de réponses (0)


En savoir plus sur Numeric Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by