Showing x and y Labels in a Correlation Matrix Plot

조회 수: 9 (최근 30일)
Yaser Khojah
Yaser Khojah 2020년 5월 9일
댓글: Ameer Hamza 2020년 5월 10일
Would you please help me to show m_{NPV} with their subscripts as below:
VariableNames={'\sigma_{1}','\sigma_{2}','\sigma_{3}','\tau_{1}','\tau_{4}','\tau_{5}','m_{NPV}'};
So, I have this code which works but I do not know how to fix m_{NPV}
% 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
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
% indSig = 0;
% for ik = 1:length(yLabelN)
%%
for ik = 1:length(Fields)
if strfind(fh.Children(yLabelN(ik)).YLabel.String,'sigma')
% indSig = indSig + 1;
fh.Children(yLabelN(ik)).YLabel.String = strrep(fh.Children(yLabelN(ik)).YLabel.String,'sigma',sprintf('\\sigma_{%d}',Fields(ik)));
end
if strfind(fh.Children(yLabelN(ik+length(Fields))).YLabel.String,'tau')
% indSig = indSig + 1;
fh.Children(yLabelN(ik+length(Fields))).YLabel.String = strrep(fh.Children(yLabelN(ik+length(Fields))).YLabel.String,'tau',sprintf('\\tau_{%d}',Fields(ik)));
end
% if strfind(fh.Children(yLabelN(ik+length(Fields))).YLabel.String,'m')
% % indSig = indSig + 1;
% fh.Children(yLabelN(ik+length(Fields))).YLabel.String = strrep(fh.Children(yLabelN(ik+length(Fields))).YLabel.String,'m',sprintf('\\tau_{%d}',Fields(ik)));
% end
end
%%
% strrep(fh.Children(yLabelN(ik)).YLabel.String,'t_','t^{*}_{1}')
% rename x labels
ik = 1:length(xLabelN)
for ik = 1:length(Fields)
if strfind(fh.Children(xLabelN(ik)).XLabel.String,'sigma')
fh.Children(xLabelN(ik)).XLabel.String = strrep(fh.Children(xLabelN(ik)).XLabel.String,'sigma',sprintf('\\sigma_{%d}',Fields(ik)));
% indSig = indSig - 1;
end
if strfind(fh.Children(xLabelN(ik+length(Fields))).XLabel.String,'tau')
fh.Children(xLabelN(ik+length(Fields))).XLabel.String = strrep(fh.Children(xLabelN(ik+length(Fields))).XLabel.String,'tau',sprintf('\\tau_{%d}',Fields(ik)));
% indSig = indSig - 1;
end
end

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 9일
Try this
% 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
% indSig = 0;
% for ik = 1:length(yLabelN)
%%
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월 10일
Thanks so much Ameer!!!
Ameer Hamza
Ameer Hamza 2020년 5월 10일
I am glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by