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

18 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Voss
Voss le 20 Mar 2022
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 commentaire
ans
ans le 20 Mar 2022
Modifié(e) : ans le 20 Mar 2022
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by