Code does not show the effect in .mlx but when run in command window it will show the effect and how to make the labels in bold

1 次查看(过去 30 天)
Hello master's
I'm not sure about this if some command won't run in .mlx becuase if i run my code with this code
clc, clearvars, close all
data1=readtable("FTIR.xlsx", 'PreserveVariableNames',true);
x1=data1.("F1(DCM_eluted)");
FF1_DCM_eluted=data1.("y1");
FF2_THF_eluted=data1.("y2");
FF3_EA_eluted=data1.("y3");
FF4_MeOH_eluted=data1.("y4");
FF5_H2O_eluted=data1.("y5");
Fwhole_sugar=data1.("y6");
figure()
h=stackedplot(x1,[FF1_DCM_eluted,FF2_THF_eluted,FF3_EA_eluted, ...
FF4_MeOH_eluted,FF5_H2O_eluted,Fwhole_sugar]);
%labels
h.XLabel = {'Wavenumber (cm^-1)'};
h.DisplayLabels = {'','','','','',''};
h.AxesProperties(1).LegendLabels = {'F1-DCM-eluted'};
h.AxesProperties(1).LegendVisible = 'on';
h.AxesProperties(1).LegendLocation = 'northwest';
h.AxesProperties(2).LegendLabels = {'F2-THF-eluted'};
h.AxesProperties(2).LegendVisible = 'on';
h.AxesProperties(2).LegendLocation = 'northwest';
h.AxesProperties(3).LegendLabels = {'F3-EA-eluted'};
h.AxesProperties(3).LegendVisible = 'on';
h.AxesProperties(3).LegendLocation = 'northwest';
h.AxesProperties(4).LegendLabels = {'F4-MeOH-eluted'};
h.AxesProperties(4).LegendVisible = 'on';
h.AxesProperties(4).LegendLocation = 'northwest';
h.AxesProperties(5).LegendLabels = {'F5-H2O-eluted'};
h.AxesProperties(5).LegendVisible = 'on';
h.AxesProperties(5).LegendLocation = 'northwest';
h.AxesProperties(6).LegendLabels = {'Whole Sugar'};
h.AxesProperties(6).LegendVisible = 'on';
h.AxesProperties(6).LegendLocation = 'northwest';
%colors
h.LineProperties(1).Color = 'r';
h.LineProperties(2).Color = 'g';
h.LineProperties(3).Color = 'b';
h.LineProperties(4).Color = 'm';
h.LineProperties(5).Color = 'c';
h.LineProperties(6).Color = 'k';
%linewidth
h.LineProperties(1).LineWidth = 2;
h.LineProperties(2).LineWidth = 2;
h.LineProperties(3).LineWidth = 2;
h.LineProperties(4).LineWidth = 2;
h.LineProperties(5).LineWidth = 2;
h.LineProperties(6).LineWidth = 2;
%this two last line of code will not show any effect in .mlx file but running in command window it will show effect
ax = findobj(h.NodeChildren, 'Type','Axes');
set(ax, 'XTick', 500:500:4000, 'XLim', [500,4000],'XDir','reverse');
of Adam Danz it will not show any effect
but if i run it in the command window it will show this
  2 个评论
Walter Roberson
Walter Roberson 2022-8-24
I am not sure why you say that it will not show any effect? The top plot does show a reversed x axes which is what you want.
Stark Volt
Stark Volt 2022-8-24
Hi walter thanks for pointing out the top picture is what I want which is I run using the command window the bottom picture is what i run in .mlx file. (Ill edit and swap the picture thanks)

请先登录,再进行评论。

采纳的回答

Yash
Yash 2023-8-31
编辑:Yash 2023-9-1
Hi Stark,
I was able to reproduce the same issue in my device.
I have found out that after you use the "set()" function, the axes properties change but the output is not updated in the MATLAB Live Script output pane.
I suggest you to use normal MATLAB script ('.m' file) instead of MATLAB Live Script ('.mlx' files) to get the correct output.
If you still want to use '.mlx' file, one workaround is to save the figure and analyse that.
% before you define h
f = figure
% at the end
saveas(f,'f.png');
You can see that the saved figure has the correct properties.
You can also flip your data by using the fliplr() function and plot that. However, please note that this won't change the xTicks.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by