How to plot histogram of each column of table and compare against the column of another table using for loop?

22 次查看(过去 30 天)
I have 2 tables with the same size (644X4). One is a old result and the latter is a new result. What I want to do is that I want to compare the result of each column of these two tables by plotting histogram using "for-loop". Eventually, I want to get four seperate histograms dipicting the comparison of old result and new result for each column.

采纳的回答

Voss
Voss 2022-3-20
It's not clear exactly what you mean by "depicting the comparison". Should it be two histograms per table column, one histogram for the old table and one for the new? Or maybe one histogram per column, showing the difference between old and new?
In any case, here is some code that can maybe serve as a starting point, which you can adapt as needed:
% creating some random tables first:
data_old = num2cell(randn(644,4),1);
t_old = table(data_old{:});
data_new = num2cell(randn(644,4),1);
t_new = table(data_new{:});
% (1) two separate histograms for each column of the tables:
figure();
for ii = 1:4
subplot(2,2,ii);
histogram(t_old{:,ii});
hold on
histogram(t_new{:,ii});
end
% (2) one histogram per column, showing the (absolute) differences:
figure();
for ii = 1:4
subplot(2,2,ii);
histogram(abs(t_old{:,ii}-t_new{:,ii}));
end
  1 个评论
ans
ans 2022-3-20
编辑:ans 2022-3-20
Thank you so much for your quick response. I am sorry for the way I post my question if you feel somehow confused. I acctually mean one histogram per column, showing the difference between old and new result of two tables.

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by