Filter löschen
Filter löschen

Figures generated in Live Script are displayed as old plots with same figure(n)

83 Ansichten (letzte 30 Tage)
I have a live script which creates graphs from several vectors. It generates 3 plots, called figure(1), figure(2) and figure(3). It used to work just fine, and generate 3 figures, which were displayed next to the script.
However, today I tried inputing a different set of vectors, and soon problems appeared:
  1. Upon running the script, variables are created and stored in the workspace as usual, but no figures appear. Only when running it 3 or 4 times figures appear.
  2. Some of the figures are transparent, when they generate at all
  3. Often, figures from previous data sets are displayed, only when the figure is opened in a window can the actual result be seen
Weirdly, other scripts are not affected by this problem
Any help is appreciated
clear
Data=tdmsread("C:\Users\f\data1.tdms",ChannelGroupName="AI",ChannelNames=["Time (us)","P_LO_VT2","P_F_VT2","M_FLOW_LO"]);
Table=Data{1,1};
Array=table2array(Table);
% Make Vector
t=Array(:,1); %Time (us)
P2=Array(:,2);
P1=Array(:,3);
M=Array(:,4);
% Smooth and convert time to s
SmoothNumber=1000;
t=((t-t(1,1))/1e6);
P1_smooth=movmean(P1,SmoothNumber);
P2_smooth=movmean(P2,SmoothNumber);
M_smooth=movmean(M,SmoothNumber)*1000;
% Plot
figure(1);
plot(t,P1_smooth);
title('P1');
xlabel('Time [s]');
ylabel('P1 [bar]');
grid on;
figure(2)
plot(M_smooth,P2_smooth)
hold on
scatter(52.5,41.8,'filled','r')
title('Flow');
xlabel('Flow [g/s]');
ylabel('P2 [bar]');
grid on
hold off
figure(3)
plot(t,P2_smooth,'b')
title('P2 and M');
xlabel('Time [s]');
ylabel('P2 [bar]');
yyaxis right
plot(t,M_smooth,'r')
ylabel('Mass flow [g/s]');
grid on
  3 Kommentare
RIchard
RIchard am 4 Jan. 2024
Bearbeitet: Walter Roberson am 4 Jan. 2024
I believe it is an problem with Live Script. Looking through all the different documentation online, I fail to find a single occurance where a Live Script has 2 y-axises. I also have this problem and recreated it with the following code:
a= 1:10;
b=rand(10,1);
c=rand(10,1)+5;
plot(a,b,a,c)
yyaxis left
plot(a,b)
yyaxis right
plot(a,c)
I cleared all outputs, closed and reopened matlab. At that point, I ran the above code once in a live script. Below is the screenshot. Note that both figures have two sets of y-axis even though only the 2nd plot should have them.
Franz Blattenberger
Franz Blattenberger am 3 Feb. 2024
I don't have access to the data anymore, but I have had a few other similar experiences with generating figures in live scripts. When the code is copied into the terminal it works flawlessly, but figure generation in the live script is unreliable in the way I described in the inital post.
I'll file a bug report.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 4 Jan. 2024
Using figure command between the plots solves this ambiguity.
a= 1:10;
b=rand(10,1);
c=rand(10,1)+5;
figure
plot(a,b,a,c)
figure
yyaxis left
plot(a,b)
yyaxis right
plot(a,c)
%% As printscreen shows here

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by