Effacer les filtres
Effacer les filtres

cell array into vector of strings

3 vues (au cours des 30 derniers jours)
William le 13 Août 2012
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
'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) = [];
data1(ii)= data.Sheet1{ii};
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?

Réponses (1)

Walter Roberson
Walter Roberson le 13 Août 2012
  1 commentaire
Walter Roberson
Walter Roberson le 13 Août 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});

Connectez-vous pour commenter.


En savoir plus sur Data Type Conversion 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