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

조회 수: 1 (최근 30일)
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.

채택된 답변

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Other Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by