Filter löschen
Filter löschen

if elseif else in Table

2 Ansichten (letzte 30 Tage)
wesleynotwise am 18 Jul. 2017
Kommentiert: Padmamalini T H am 31 Jan. 2020
I have a column in my table containing numerical data, where I want to make them into 4 specific groups in a new column in the same table. I do not know how to write the code, but have attempted the following failed codes. Please correct me.
num_rows = size(Table1.Time,1) %count the number of rows in Table 1
for i=1:1:num_rows
if T1.Time < 5
T1.TimeNew = 5; % Group 1, return in a new column in Table 1
elseif T1.Time >= 5 & T1.Time <15
T1.TimeNew = 15; % Group 2
elseif T1.Time >= 15 & T1.Time <25
T1.TimeNew = 25; % Group 3
else T1.TimeNew = 30; % Group 4 (for any data >=25)

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 18 Jul. 2017
Bearbeitet: Andrei Bobrov am 18 Jul. 2017
ii = discretize(T.Time,[-inf,5,15,25,inf])
V = [5,15,25,30]';
T.TimeNew = V(ii);
  5 Kommentare
Jessica Blasco
Jessica Blasco am 14 Mai 2018
thanks!! He also helped me with a similar problem!! :)
Padmamalini  T H
Padmamalini T H am 31 Jan. 2020
thank you sir. it helped my problem too

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

lyda am 19 Mai 2019
I have one table with many raws and columns.
I want to create a new table.
if a cell=111 return to me this raw
I don't know how to write this.
for i=2:1143; %column 2 to raw 1143
if everything(i)==111; %"everything" is a table with all features
thank you!

Community Treasure Hunt

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

Start Hunting!

Translated by