Cell to double for table2array operation, then compile two matice into a .mat file.

4 ビュー (過去 30 日間)
Jered Willoughby
Jered Willoughby 2019 年 7 月 25 日
回答済み: Deepak 2025 年 6 月 4 日
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.

回答 (1 件)

Deepak
Deepak 2025 年 6 月 4 日
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.

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by