How to Convert a big cell char array With in Table form in Each Column in MATLAB

조회 수: 3 (최근 30일)
Hello. I have import Data from website. I need to convert the Char array in Table with Values in Each Column
For Example In the following data I have 2x8 cell. The first Cell Predicted Class is the Column name and Cat is the Value.
The second Cell in first will be Column name Maximum, Minimum and Mean Value corresponding to there Values.
The Third Cell in first Row Predicted Class is the Column name and Fighter is the Value. The fourth Cell Fighter Levels, Fighter Values, Maximum, Minimum and Mean Value
The first row is C1 is the first Class and the 2nd row is C2 is the Second Class so it should be in loop to save the data for multiple classes.
Can anybody help me with that.
as shown in the following picture

답변 (1개)

Dr. JANAK TRIVEDI
Dr. JANAK TRIVEDI 2023년 2월 3일
편집: Walter Roberson 2023년 2월 3일
You can use the split and str2double functions in MATLAB to split the data and convert the values to a table. Here's an example:
data = {'Predicted Class','Cat','Maximum','Minimum','Mean Value',...
'Predicted Class','Fighter','Levels','Values','Maximum','Minimum','Mean Value'};
% Split the data by the delimiter ','
splittedData = split(data,',');
% Get the number of rows and columns from the splitted data
[rows,cols] = size(splittedData);
% Initialize a cell array to store the table data
tableData = cell(rows/2, cols/2);
% Loop through the splitted data and store the values in the tableData cell array
for i = 1:2:rows
for j = 1:2:cols
tableData{(i+1)/2, (j+1)/2} = splittedData{i,j};
end
end
% Convert the values in the tableData cell array to a table
table = cell2table(tableData);
% Convert the values in the table to numeric if possible
table.Variables = str2double(table{:,:});
  댓글 수: 2
Hammad Younas
Hammad Younas 2023년 2월 3일
@Dr. JANAK TRIVEDI it is not working. Have you check the dataset.
Please provide solution for the attached Dataset
Hammad Younas
Hammad Younas 2023년 2월 6일
@Walter Roberson @Dr. JANAK TRIVEDI this code does not work because my data has no comma ',' Can you please modified this?

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by