Updating the histogram in a correlation matrix after creating the matrix plot
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Yaser Khojah
am 10 Mai 2020
Kommentiert: Mehmed Saad
am 11 Mai 2020
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
2 Kommentare
Akzeptierte Antwort
Mehmed Saad
am 11 Mai 2020
[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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!