cell array into vector of strings
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Walter Roberson
am 13 Aug. 2012
See http://www.mathworks.co.uk/matlabcentral/answers/45873-evaluation-of-a-for-loop for why your loop is failing.
1 Kommentar
Walter Roberson
am 13 Aug. 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
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!