How to do Conversion of numeric values to string within cell array?

2 visualizaciones (últimos 30 días)
Matt b
Matt b el 27 de Jun. de 2018
Comentada: Guillaume el 27 de Jun. de 2018
Dear MATLAB experts,
I have a cell array of dimensions {1x162} where each column is a string value. The "strings" are read from a data file containing alpha numeric characters (e.g., data looks like: 1, 2, 3, NA, NA, NA, 4, 5, -.20, -.25, -.26, NA, NA, etc).
I am updating elements of this cell array by replacing values with new ones. When do I this, the elements in the cell array appear like so:
'1' '2' '3' 'NA' 'NA' NA' '4' '5' 1x1cell 1x1cell 1x1cell 'NA' 'NA' etc, where the values I am replacing in this cell array do not take the same format as the other values which I assume are being treated as strings, and the values that I am replacing into this array are indeed numeric.
How can I get MATLAB to treat these new values as the same format as the contents already there? Is there an easy way to input these values as strings rather than numeric? In other words, how can I convert the contents of the 1x1 cells that have appeared within my cell array to appear as the other entries, with '' around them. I have poured over several different ways of doing this and I can't seem to get any of them to work.
Any help that you can provide is greatly appreciated.
Thank you,
-Matt
  5 comentarios
Matt b
Matt b el 27 de Jun. de 2018
If you think it would help, here it is. Thanks.
Guillaume
Guillaume el 27 de Jun. de 2018
If what you are doing is replacing some elements of line 18 of a text file, then yes you are overcomplicating it.
If I understand correctly the replacement come from cell array psct which it seems contains numeric data (in which case, the cell array would be better as a matrix for efficiency).
You list elements 109 to 162 (= 54 elements) of the original line to be replaced by elements 1 to 24 (= 25 elements) of psct. Something doesn't tally. How are the elements to be replaced exactly determined?
The whole thing can be done in very few lines once we have all the details.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 27 de Jun. de 2018
Why not just use strsplit:
data = importdata('data.txt', ' ', 18)
str = data{end} % Extract last line
ca = strsplit(str, ' ') % Load into cell array

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by