Conversion to double from cell is not possible.

Hi there, I am new in MATLAB and I have this problem "Conversion to double from cell is not possible", I uploaded a matrix with readtable and I delimited with (;). Then It made a matrix of 10200x3, in the third column I have values with "comma" decimal (25,7). I used str2double to change from cell array to double array, but the new value is (257). I would like to get the same value (25,7). Somebody could help me please.

댓글 수: 2

Mind sharing a screenshot/file of that table ?
Hello Madhan, I don't mind here I attach the file and the screenshot. Thanks

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam Danz
Adam Danz 2020년 7월 8일
편집: Adam Danz 2020년 7월 8일

0 개 추천

There might be an option in readtable() or within the opts input that can specify what decimal character to use when reading in the data. I looked briefly but couldn't find what I'm imagining but I do recall that such an option exists. That would be the best solution, if possible.
To fix the data described in your question, first replace the commas in column 3 with periods.
% "C" is your cell array
C(:,3) = strrep(C(:,3),',','.');
then proceed with str2double.
d = str2double(C(:,3));
For tables
T.Var3 = strrep(T.Var3,',','.');
T.Var3 = str2double(T.Var3);

댓글 수: 3

Hello Adam, I did it. But the answer in the first step "C(:,3) = strrep(C(:,3),',','.');" is the following
Warning: Inputs must be character vectors, cell arrays of character vectors, or string arrays.
Error using strrep
Conversion to double from table is not possible.
Hi Adam, I did it. Thank you a lot :)
That's because your data is not a cell array. It's a table.
I've updated my answer.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fabian Moreno
Fabian Moreno 2020년 7월 8일

0 개 추천

I have one more question, when I Convert strings to double precision values, the result is a number like this (23.700). I'm trying to take out the extra zeros with (round). But the zeros continue there. Any suggestion to eliminate the zeros?.

댓글 수: 6

The zeros should go away after you convert to double. How are you doing that conversion? If your original question has been answered, please consider accepting the answer.
The question has not been aswer, and I did the conversion in the same way that you taught me. Here is the way that I did
PADPE_Temp=readtable('PADPE_Temp.csv','Headerlines',8,'delimiter','/;');
>> PADPE_Temp.Var3 = strrep(PADPE_Temp.Var3,',','.');
PADPE_Temp.Var3 = str2double(PADPE_Temp.Var3);
The result is for example, 29.0000; 27.000...
I already tried "sprintfc('%0.1f',(x))", but It convert the number into a cell array again.
Now I'm confused. I thought " Hi Adam, I did it. Thank you a lot :)" meant that the problem was solved.
The problem with the trailing 0s is a new problem.
The trailing 0s is likely a formatting issue.
Thank you Adam you helped me a lot. Everything was fine. :D
xD
Adam Danz
Adam Danz 2020년 7월 10일
Glad I could help! :)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2020년 7월 8일

댓글:

2020년 7월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by