Adding a new column to a table

20 Ansichten (letzte 30 Tage)
Daniela Valdez
Daniela Valdez am 25 Feb. 2021
Kommentiert: Star Strider am 25 Feb. 2021
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

Antworten (1)

Star Strider
Star Strider am 25 Feb. 2021
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 Kommentare
Daniela Valdez
Daniela Valdez am 25 Feb. 2021
Thnks! Appreciate it
Star Strider
Star Strider am 25 Feb. 2021
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by