How to extract data from a text file and use logical if-else statement after some calculations and creating a new column in the data

2 views (last 30 days)
I have a text file stress_data.txt attached herewith in which I have 5 columns. Out of these 5 columns I need to find 1/3*(Col 3 + Col 4 +Col 5) = Col 6, which is a new column.
Now I need to put logical if-else statements for the variable in Col 6 to analyse and interpret a phenomena.
I dont know :
1) how to execute the calculation "1/3*(Col 3 + Col 4 +Col 5) = Col 6"
2) extract the values of Col 6
3) execute if-else statement to the variable in Col 6.
I have tried this but it is not working :
load stress_data.txt
stress_data = readtable('stress_data.txt')
stress_data.HP = stress_data{:,3:end}/3
Please help.
N.B I just need the step by step syntax as of how to execute the whole thing mentioned above.

Accepted Answer

Adarsh Ghimire
Adarsh Ghimire on 7 Mar 2019
data = load ('stress_data.txt');
col6 = (1/3).*(data(:,3)+data(:,4)+data(:,5));

More Answers (0)

Categories

Find more on Migrate GUIDE Apps 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!