MATLAB: Conversion problem of data types of an array

conversiondata type

Hi all, I read with textscan from a text file to get an array. I received this error report at first
"All contents of the input cell array must be of the same data type."
for my array "data_A".
data_A:
522x1 double 522x1 double 522x1 cell 522x1 double
I tried to do this:
data_A(:,3) = str2double(data_A(:,3));
and I received this report:
"Conversion to cell from double is not possible."
Hence, I tried to use cell2mat:
data_A(:,3) = cell2mat(data_A(:,3));
for which I got the same error again:
"All contents of the input cell array must be of the same data type."
It would be so kind, if anyone could look into the matter. Any help and tips are very much appreciated. =)
Best regards,
Boon

Best Answer

I'm with dpb, fix the code so that it does not make a mess in the first place rather than trying to fix the mess.
It sounds like you're importing some data with something like textscan which needs you to explicitly specify the format of the text file. Since R2013b, matlab has included readtable which is usually capable of figuring out the format (and headers) on its own. Perhaps, moving to more modern constructs would solve the problem.
Most time all that is needed is:
t = readtable(yourfile);
Nothing more, and if readtable gets it wrong, you can guide it with detectImportOptions and specify the actual format for these columns where it gets it wrong.