MATLAB Answers

How is the average and normalization of each column in the table using "for" loop?

14 views (last 30 days)
expert on 18 Nov 2019
Edited: Srijith Kasaragod on 5 Aug 2021
I have a table with 50x10. In the table, first column is Genes and the second column will be reference column for normalization. Other 8 column will divide reference column. Afterward, this table will be normalized and each column will be averaged after normalization. Therefore there will be one row and 8 columns. How can I do this process in a table. Is it necessary to convert this table to a matrix or dataset, or can we solve it with a simle loop?
I m trying this code for table:
%import data
data = readtable("data.xlsx", "UseExcel", false);
%I coverted table to matrix form by deleting first row
for i = 2:10
res(:,i-1) = data(:,i)./data(:,1);
res_m = mean(res);
Bu code is not working as I want and I want to try this with table or dataset form
% Genes gsm335244 gsm335245 gsm335246
% A1CF 1,194 0,848 0,905
% A2M 0,325 6,301 0,607
% A4GALT 1,048 0,592 1,964
expert on 18 Nov 2019
I converted data to a mtrix form, I did calculation with these code:
for i = 2:10
res(:,i-1) = data(:,i)./data(:,1);
res_norm = normalize(res,'norm',Inf);
res_m = mean(res_norm);
in the res_m data, there are means of each column but there are nocolumn legends and I tried some plots but I could not obtain good plot. I think it is better use dataset or table form. What do you think?

Sign in to comment.

Answers (1)

Srijith Kasaragod
Srijith Kasaragod on 4 Aug 2021
Edited: Srijith Kasaragod on 5 Aug 2021
From my understanding you have a 50x10 table, columns 3 to 10 must be divided with corresponding elements from column 2, followed by taking the mean of those eight columns. The required output can be obtained by simple manipulation of the table. Following code implements the steps:
%reading the table
data= readtable('data.xlsx');
%perform normalization and take mean of columns
data= mean(data{:,3:end})
Final result is a table of size 1x8 which contains mean of columns 3 to 10.

Community Treasure Hunt

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

Start Hunting!