I have the following database (Male_Data), its a 3101x16 table.
I want to add a new column in which I get values between 1 and 3 depending on the value I have on the QTCorrected column.
1 if the value is between 330 - 360
2 if the value is between 361 - 390
3 if the value is between 391 - 470.
% This is all I can think of
% The name of the column I want to add is QTSyndrome
Male_Data.QTSyndrome = Male_Data.QTCorrected () %I'm thinking about adding some kind of if statement inside the
% parenthesis but my attempts haven't been succesful so far
Any help is appreciated
Thanks

답변 (1개)

Star Strider
Star Strider 2021년 2월 25일

1 개 추천

One approach:
T1 = table(randi([330 470],10,1), 'VariableNames',{'QTcorrected'}); % Create Data
QTc = @(x) 1*((x>=330)&(x<=360)) + 2*((x>=361)&(x<=390)) + 3*((x>=391)&(x<470)); % Classify
T1.NewColumn = QTc(T1.QTcorrected); % Add Variable
.

댓글 수: 5

Daniela Valdez
Daniela Valdez 2021년 2월 25일
This is exactly what I was looking for! I appreciate it
Hey! If I wanted to add the FileName column and have it match the row with the other data, how would you do it, here's what I'm doing
Male_Data_QTC = table(randi([330 470],3101,1), 'VariableNames',{'QTCorrected', 'FileName'}); % Create Data
QTc = @(x) 1*((x>=330)&(x<=360)) + 2*((x>=361)&(x<=390)) + 3*((x>=391)&(x<470)); % Classify
FileName = addvars(Male_Data.FileName)
Male_Data_QTC.QTSyndrome = QTc(Male_Data_QTC.QTCorrected) + FileName(Male_Data_QTC.FileName); % Add Variable
Star Strider
Star Strider 2021년 2월 25일
As always, my pleasure!
I’m not certain about the ‘Fliename’ column, or that you’d need to add it separately, since if you use readtable to import the file in the image, it should already exist. There shouldn’t be any reason to add it again.
I’d have to have your data to experiment with to be certain, however simple horizontal concatenation would likely be easiest, if ‘Filename’ was already a table object.
See Build Table by Assigning Variables Individually for details on how best to add variables to existing table objects.
Daniela Valdez
Daniela Valdez 2021년 2월 25일
Thnks! Appreciate it
Star Strider
Star Strider 2021년 2월 25일
As always, my pleasure!

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

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

제품

릴리스

R2015b

태그

질문:

2021년 2월 25일

댓글:

2021년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by