cell array into vector of strings

1 次查看(过去 30 天)
William
William 2012-8-13
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

回答(1 个)

Walter Roberson
Walter Roberson 2012-8-13
  1 个评论
Walter Roberson
Walter Roberson 2012-8-13
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by