# Convert cell char array With Column in Table form MATLAB

2 visualizaciones (últimos 30 días)
Hammad Younas el 2 de Feb. de 2023
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.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

dpb el 2 de Feb. de 2023
Editada: dpb el 2 de Feb. de 2023
This is pretty simple with the newer string facilities -- as an example, for the first variable, use something like
animal=extractAfter(DatasetWebsite(:,1),'Animal: ');
It should be obvious how to proceed with the remainder; the one with the multiple values will need only slightly more complicated logic although here's a place to illustrate another new(ish) feature so...
>> extract(DatasetWebsite(:,2),digitsPattern)
ans =
2×3 cell array
{'1000'} {'1000'} {'1000'}
{'1000'} {'1000'} {'1000'}
>>
and then just wrap the latter inside
>> str2double(ans)
ans =
1000.00 1000.00 1000.00
1000.00 1000.00 1000.00
>>
and you've got the numeric array. This could be one line of code, of course...
statistics=str2double(extract(DatasetWebsite(:,2),digitsPattern));
##### 7 comentariosMostrar 5 comentarios más antiguosOcultar 5 comentarios más antiguos
dpb el 3 de Feb. de 2023
Well, show us what you tried...
Hammad Younas el 6 de Feb. de 2023
@dpb Here is the following code i have tried
% 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{:,:});

Iniciar sesión para comentar.

### Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by