Conversion to double from cell is not possible.
    120 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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 Commenti
Risposta accettata
  Adam Danz
    
      
 il 8 Lug 2020
        
      Modificato: Adam Danz
    
      
 il 8 Lug 2020
  
      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 Commenti
  Adam Danz
    
      
 il 8 Lug 2020
				That's because your data is not a cell array.  It's a table. 
I've updated my answer. 
Più risposte (1)
Vedere anche
Categorie
				Scopri di più su Data Type Conversion in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
