Cell to double for table2array operation, then compile two matice into a .mat file.
    4 views (last 30 days)
  
       Show older comments
    
I need to change a datatype from cell to double (or vice-versa) in order to get my bagged tree function to work. This is needed to create/sparse a table2array from the original .csv file.
0 Comments
Answers (1)
  Deepak
 on 4 Jun 2025
        I understand that you are trying to use a bagged tree function in MATLAB, but facing issues due to mismatched data types—specifically, needing to convert between cell and double to successfully use table2array on your CSV data.
To resolve this issue and ensure compatibility, we can convert the relevant cell columns to double before applying table2array.
Below is a sample MATLAB code to achieve the same:
% Read the CSV file into a table
T = readtable('yourfile.csv');
% Convert specific cell columns to double
if iscell(T.YourColumn)
    T.YourColumn = cellfun(@str2double, T.YourColumn);
end
% Convert table to array
A = table2array(T);
Also, we can convert numeric double data to a cell format using the below code:
T.YourColumn = num2cell(T.YourColumn);
Please find attached the documentation of functions used for reference:
I hope this assists in resolving the issue.
0 Comments
See Also
Categories
				Find more on Workspace Variables and MAT Files in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
