Showing x and y Labels in a Correlation Matrix Plot

6 Ansichten (letzte 30 Tage)
Yaser Khojah
Yaser Khojah am 9 Mai 2020
Kommentiert: Ameer Hamza am 10 Mai 2020
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

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 9 Mai 2020
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

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by