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.
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!