필터 지우기
필터 지우기

How to convert cell char array in Table With Column

조회 수: 10 (최근 30일)
Hammad Younas
Hammad Younas 2023년 2월 2일
댓글: Hammad Younas 2023년 2월 3일
Hello. I hope you are doing Well. 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 2x2 cell. The first Cell Predicted Class is the Column name and Airplane is the Value.
The second Cell will be Column name Maximum Amp and Time Value corresponding to there Values.
The C1 is the first Class and C2 is the Second Class so it should be in loop to save the data for multiple classes.
Can anybody help me with that.
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 2월 2일
y=load('Data.mat').Datawebsite
y = 2×2 cell array
{'C1 Predicted Class: Airplane' } {' Maximum Amp: [-14.5052] Time (s): 2.5988 '} {'C2 Predicted Class: AirplaneCombat'} {' Maximum Amp: [-30.1052] Time (s): 4.853 ' }
It's not clear how you want to store this data in Table. What is supposed to be the format of the Table? Direct conversion column wise?
out=cell2table(y)
out = 2×2 table
y1 y2 ______________________________________ ______________________________________________ {'C1 Predicted Class: Airplane' } {' Maximum Amp: [-14.5052] Time (s): 2.5988 '} {'C2 Predicted Class: AirplaneCombat'} {' Maximum Amp: [-30.1052] Time (s): 4.853 ' }
Please give a sample output.
Hammad Younas
Hammad Younas 2023년 2월 2일
The data save in Table form like this one. I have attached the new data Please add code for this one

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

채택된 답변

KSSV
KSSV 2023년 2월 2일
You can use regexp to extract the data.
load('Data.mat')
[m,n] = size(Datawebsite) ;
predictedClass = cell(m,1) ;
maximumAmp = zeros(m,1) ;
time = zeros(m,1) ;
expression1 = ':\s*(\w+)';
expression2 = '-?\d+\.\d+';
for i = 1:m
string1 = Datawebsite{i,1} ;
tokens = regexp(string1,expression1,'tokens');
predictedClass{i} = tokens{1}{1};
string2 = Datawebsite{i,2} ;
tokens = regexp(string2,expression2,'match');
maximumAmp(i) = str2double(tokens{1});
time(i) = str2double(tokens{2});
end
T = table(predictedClass,maximumAmp,time)
  댓글 수: 4
KSSV
KSSV 2023년 2월 3일
You have the code for your asked case...you can extends the same to your case. It is straight forward.
Hammad Younas
Hammad Younas 2023년 2월 3일
@KSSV I am unable to do that, Thats why i posted the other question.
Can you please help me in that

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

추가 답변 (0개)

카테고리

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