cell array into vector of strings

1 visualización (últimos 30 días)
William
William el 13 de Ag. de 2012
Greetings,
I am having a great deal of difficulty importing text data from excel into a vector of strings that I can index.
I am using
data = importdata('data.xls')
to get a struct with one cell [192 x 1 cell]
to access a specific string I use
data.Sheet1{1}
returns
'236C7 '
I cannot directly convert this to deicmal due to the space at the end. The code I am using to scrub the data of that is below
c_limit = size(data.Sheet1);
data1 = zeros(cal_limit,1);
for ii = 1:c_limit
temp_c_string = data.Sheet1{ii};
length_o_value = size(temp_cal_string);
for hh = 1:length_o_value
if isspace(temp_c_string(hh))== true
temp_c_string(hh) = [];
end
data1(ii)= data.Sheet1{ii};
end
end
It keeps giving me an error that proclaims that I am referencing a number out of matrix dimension. I know this but I am referring to a string and it seems to not want to let me..
is there a better way to get the dat from this cell into a vector of strings? or an array of strings?
Thanks

Respuestas (1)

Walter Roberson
Walter Roberson el 13 de Ag. de 2012
  1 comentario
Walter Roberson
Walter Roberson el 13 de Ag. de 2012
His code has a few other mistakes, such as using size() instead of length(), and not using the value of temp_c_string after it is computed. But overall your solution was probably the correct one, Lucas, to use deblank()
for ii = 1 : length(data.Sheet1)
data1(ii) = deblank(data.Sheet1{ii});
end

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by