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

1 次查看(过去 30 天)
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);
end
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
  2 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2019-11-18
编辑:KALYAN ACHARJYA 2019-11-18
In the RHS, what does it mean?
res(:,i-1)=data(:,i)./data(:,1); % RHS > Same Parameters
Please attach data file
expert
expert 2019-11-18
编辑:expert 2019-11-18
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);
end
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?

请先登录,再进行评论。

回答(1 个)

Srijith Kasaragod
编辑:Srijith Kasaragod 2021-8-5
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{:,3:end}=data{:,3:end}./data{:,2};
data= mean(data{:,3:end})
Final result is a table of size 1x8 which contains mean of columns 3 to 10.

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by