Creating a new column in a table using if condition and equation
Show older comments
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)
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!