MATLAB Answers

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

15 ビュー (過去 30 日間)
Yaser Khojah
Yaser Khojah 2020 年 5 月 10 日
コメント済み: Mehmed Saad 2020 年 5 月 11 日
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 件のコメント

Yaser Khojah
Yaser Khojah 2020 年 5 月 11 日
Dear Mehmed can expalin how much your help has saved me.... Thanks a lot

サインインしてコメントする。

採用された回答

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 件のコメント

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by