Updating the histogram in a correlation matrix after creating the matrix plot

4 次查看(过去 30 天)
I have this code which makes a correlation matrix. I want to create the matrix plot as below and later I want to update the histogram with different sets. Any idea please?
% your example code
Fields = [1, 4, 5];
Fields_time = Fields +16;
MT_All = rand(100,26);
% MT_All = rand(100,9);
VariableNames={'sigma','sigma','sigma','tau','tau','tau','mNPV'}; % changed to ensure valid syntax
Mat_All_1_4_5 = [MT_All(:,Fields), MT_All(:,Fields_time), MT_All(:,end-1)];
figure
c = corrplot(Mat_All_1_4_5, 'varNames', VariableNames);
% get current figure handle
fh = gcf;
% find x and y label strings that are not empty within subplots
yLabelN = find(cell2mat(arrayfun(@(dIn)~isempty(dIn.YLabel.String),fh.Children,'UniformOutput',false)));
xLabelN = find(cell2mat(arrayfun(@(dIn)~isempty(dIn.XLabel.String),fh.Children,'UniformOutput',false)));
% rename y labels
for ik = 1:length(yLabelN)
if ik <= 3
fh.Children(yLabelN(ik)).YLabel.String = sprintf('\\sigma_{%d}',Fields(ik));
fh.Children(xLabelN(ik)).XLabel.String = sprintf('\\sigma_{%d}',Fields(ik));
elseif ik <=6
fh.Children(yLabelN(ik)).YLabel.String = sprintf('\\tau_{%d}',Fields(ik-3));
fh.Children(xLabelN(ik)).XLabel.String = sprintf('\\tau_{%d}',Fields(ik-3));
else
fh.Children(yLabelN(ik)).YLabel.String = sprintf('m_{NPV}');
fh.Children(xLabelN(ik)).XLabel.String = sprintf('m_{NPV}');
end
end

采纳的回答

Mehmed Saad
Mehmed Saad 2020-5-11
[r,p,h] = corrplot(Mat_All_1_4_5, 'varNames', VariableNames);% change here pass handle output
h contains handles to plotted graphic object
type h in command window
h
You will see
h =
7×7 graphics array:
Histogram Line Line Line Line Line Line
Line Histogram Line Line Line Line Line
Line Line Histogram Line Line Line Line
Line Line Line Histogram Line Line Line
Line Line Line Line Histogram Line Line
Line Line Line Line Line Histogram Line
Line Line Line Line Line Line Histogram
Now all the diagonal elements are histogram
either generate logical diagonal matrix and index it or use subs (1,1) (2,2) (3,3),... (7,7)
For example
h(2,2).Data = rand(100,1)

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by