I want to tranfer the data type of the selected columns of the table from cellstring to numeric.
However, I am stuck by this error: cannot convert from double to cell
selected_cols={'Dailypeakwindspeed', 'Dailyprecip', ... 'Dailysnowdepth', 'Dailysnowfall'};% tb_daily is my table
tb_daily(:,selected_cols)= varfun( @str2double, tb_daily,...'InputVariables', selected_cols); % this line errors
I found out that tb.Var is not equivalent with tb{:,'Var'}, which is shown by the example below.
tb=table({'1';'2'}); tb(:,'Var1')= table([1;2]) % this gives error: cannot convert from double to cell
tb{:,'Var1'}= [1;2] % this gives error: cannot convert from double to cell tb.Var1= [1;2] % this is successful! Weird!!!
Too weird!
One solution would be to use the dot syntax, but that means I have to repeat this for every selected column, therefore not satisfied.
Best Answer