MATLAB Answers

'String scalar or character vector must have valid interpreter syntax:' for Sigma

81 ビュー (過去 30 日間)
Yaser Khojah
Yaser Khojah 2019 年 10 月 24 日
コメント済み: Yaser Khojah 2019 年 10 月 29 日
Hello,
I have this code, and I'm trying to type the sigma symbol, but it is not working. It works for different figures but not this one. Can you please help.
MT_All = rand(100,9);
VariableNames={'\sigma_{1}','\sigma_{2}','\sigma_{3}','\sigma_{4}','T_{1}','T_{2}','T_{4}','T_{5}','ENPV'};
Mat_All_1_4_5 = MT_All(:,[1, 2, 4, 5, 17, 18, 20, 21, 25]);
figure
corrplot(Mat_All_1_4_5, 'varNames', VariableNames);

  0 件のコメント

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

採用された回答

Robert U
Robert U 2019 年 10 月 24 日
Hi Yaser Khojah,
I found the following description in the documentation of corrplot():
"Variable names to be used in the plots, specified as the comma-separated pair consisting of 'varNames' and a cell array of character vectors with numVars names. All variable names are truncated to the first five characters."
After truncation the interpreter only gets "\sigm" which can neither be interpreted as greek letter nor being a valid interpreter syntax.
In order to fix that you would have to enter each sublot being in either 1st column or last row and change the xlabel.String-property or ylabel.String-property, respectively.
% your example code
MT_All = rand(100,9);
VariableNames={'sigma','sigma','sigma','sigma','T_{1}','T_{2}','T_{4}','T_{5}','ENPV'}; % changed to ensure valid syntax
Mat_All_1_4_5 = [MT_All;[1 2 4 5 17 18 20 21 25]];
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)
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}',indSig));
end
end
% rename x labels
for ik = 1:length(xLabelN)
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}',indSig));
indSig = indSig - 1;
end
end
Kind regards,
Robert

  4 件のコメント

表示 1 件の古いコメント
Yaser Khojah
Yaser Khojah 2019 年 10 月 29 日
Dear Robert,
Is there anyway to show 'T_{1}' as 't^{*}_{1}'. It works only for the t_{1} but does not work for both.
Robert U
Robert U 2019 年 10 月 29 日
Hi Yaser Khojah,
you can adjust the above approach and change the label-strings from 'T_{1}' to 'T^{*}_{1}' by
strrep(fh.Children(yLabelN(ik)).YLabel.String,'T_','T^{*}_')
Kind regards,
Robert
Yaser Khojah
Yaser Khojah 2019 年 10 月 29 日
Dear Rober. Thank you so much and it is working finally.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by