MATLAB Answers

Trying to use Array Calculations

5 views (last 30 days)
Thallon Pitchure
Thallon Pitchure on 28 Jan 2020
Commented: Mohammad Sami on 28 Jan 2020
I am trying to do calculations from data import from a .csv file. I mport the code and filter it to make an array with the data that is necessary for my calculations. I am trying to take each column and square each row of the column and then I would like to store the solution in a new column next to the input. If I am unclear I apologize. My goal is to take Ank_Pow1, Ank_pow2, and Ank_Pow_Gen; then square each cell and store the found value in the cell next to input.
I was trying to use T.TestAvg = mean(T{:,2:end},2) as my example but I do not understand the ,2 past the { }. If someone could explain please and also the example does row calulations and not column. If you could please help, I would greatly appreciate it. Thank you and have a pleasant day.
This is the code I have so far.
tbl_unfiltered = readtable([pathname filename], 'ReadVariableNames', 1);
tbl_all_variables = tbl_unfiltered (1:36,[4 5 6 8]);
tbl_Control = tbl_unfiltered(18:36,4:6);
tbl_COPD = tbl_unfiltered(1:16,4:6);
tbl_Cont_speed = tbl_unfiltered(18:36,8);
tbl_COPD_speed = tbl_unfiltered(1:16,8);
Control_array = table2array(tbl_Control);
COPD_array = table2array(tbl_COPD);
Control_sum = sum(Control_array);
COPD_sum = sum(COPD_array);
and this is a sample of my input data.
  1 Comment
Mohammad Sami
Mohammad Sami on 28 Jan 2020
For squaring the elements use .^2
t.var1_2 = t.var1.^2;
For reorderign the columns
t = t(:,[4 3 2 1]); % change the col orders. 4th column comes first.

Sign in to comment.

Answers (0)


Community Treasure Hunt

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

Start Hunting!