Creating a new column in a table using if condition and equation
28 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi I have a table with daily data for a year: 365 rows x 4 columns. I need to create a new column which is defined by a function that I will show below and takes the data from other columns in the table.
For example lets say the columns of the table are labelled: A,B,C,D and the new column would be E
If D<1.2 then E=1
If D>6.5 then E=0.23
anything else E=1.18exp(-0.18*D)
This is what I have so far but the new column is only doing the last calculation and isnt following my limit values.
T = readtable('Data.csv');
if T.D <1.2
T.E = 1.0;
elseif T.D >6.5
T.E = 0.23;
else T.E = 1.18*exp(-0.18*T.D);
end
disp(T)
0 commentaires
Réponse acceptée
Stef1998
le 26 Nov 2021
3 commentaires
Peter Perkins
le 28 Nov 2021
I would think you would want
T.F(idx3) = 1000 * (2501 - 2.36 * T.B(idx3))
If T.F and T.B are in one table, they have the same size, but T.F(idx3) is shorter. You need to assign from the same subset of T.B, I think.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!