Warning: An error occurred while drawing the scene: Error in json_scenetree: Could not find node in replaceChild
Mostra commenti meno recenti
My matlab version is 2020(a).
It always calls the "Warning: An error occurred while drawing the scene: Error in json_scenetree: Could not find node in replaceChild" .
I had try the previous solution "opengl software" , but it didn't work.
This is the code I complie.
Is the code have problem or matlab problem.
How can I deal with this problem?
clear all
close all
clc
ATT = 1;
DATE = datestr(now, 30);
mdl = 'quarter_car';
open_system(mdl)
agentblk = [mdl '/RL Agent'];
numObs = 5;
numAct = 2;
observationInfo = rlNumericSpec([numObs 1],'LowerLimit',-inf*ones(numObs,1),'UpperLimit',inf*ones(numObs,1));
observationInfo.Name = 'observation';
actionInfo = rlFiniteSetSpec({[0;0],[0;1]});
actionInfo.Name = 'actor';
env = rlSimulinkEnv(mdl,agentblk,observationInfo,actionInfo);
Ts = 0.01;
Tf = 10;
rng(0)
statePath = [
imageInputLayer([numObs 1 1],'Normalization','none','Name','observation')
fullyConnectedLayer(50,'Name','CriticObsFC1')
reluLayer('Name','CriticRelu1')
fullyConnectedLayer(30,'Name','CriticObsFC2')];
actionPath = [
imageInputLayer([numAct 1 1],'Normalization','none','Name','action')
fullyConnectedLayer(30,'Name','CriticActFC1')];
commonPath = [
additionLayer(2,'Name','add')
reluLayer('Name','CriticCommonRelu')
fullyConnectedLayer(1,'Name','output')];
criticNetwork = layerGraph(statePath);
criticNetwork = addLayers(criticNetwork,actionPath);
criticNetwork = addLayers(criticNetwork,commonPath);
criticNetwork = connectLayers(criticNetwork,'CriticObsFC2','add/in1');
criticNetwork = connectLayers(criticNetwork,'CriticActFC1','add/in2');
criticOpts = rlRepresentationOptions('LearnRate',0.001,'GradientThreshold',1);
obsInfo = getObservationInfo(env);
actInfo = getActionInfo(env);
critic = rlQValueRepresentation(criticNetwork,obsInfo,actInfo,'Observation',{'observation'},'Action',{'action'},criticOpts);
agentOptions = rlDQNAgentOptions(...
'SampleTime',Ts,...
'TargetSmoothFactor',1e-3,...
'ExperienceBufferLength',1e6,...
'UseDoubleDQN',false,...
'DiscountFactor',0.5,...
'MiniBatchSize',64);
agentOpts.NoiseOptions.Variance = 0.5;
agentOpts.NoiseOptions.VarianceDecayRate = 1e-3;
agent = rlDQNAgent(critic,agentOptions);
maxepisodes = 2000;
maxsteps = ceil(Tf/Ts);
trainingOptions = rlTrainingOptions(...
'MaxEpisodes',maxepisodes,...
'MaxStepsPerEpisode',maxsteps,...
'ScoreAveragingWindowLength',5,...
'Verbose',false,...
'Plots','training-progress',...
'StopTrainingCriteria','AverageReward',...
'StopTrainingValue', 25000);
trainingStats = train(agent,env,trainingOptions);
simOptions = rlSimulationOptions('MaxSteps', maxsteps);
experience = sim(env,agent,simOptions);
1 Commento
Chris
il 28 Set 2025
Spostato: Walter Roberson
il 16 Gen 2026
I have the same problem, but I am not usung simulink. I have just downloaded 2025b and I get this error usualy after re-sizing a figure. Does not occur in older versions
Risposte (3)
Mayank
il 16 Gen 2026
Ok, I narrowed it down the cause of the problem. The error occurs when using WebGL renderer which is the only option since 2025a onwards. The error occurs when any axis' xtick's (or maybe even other properties) are set to NaN. For example, with the following code I can recreate the error. The only thing is that the commands should be run one by one and not as a script.
f = figure;
aj = plot(1:5);
ax = gca;
ax.XTick = NaN;
set(ax,'Visible','off')
It would be helpful if the code threw an error when the XTick is set to NaN, rather than later when it is rendered, because there is no way to know which graphics object is causing the error.
Mayank
Emmanouil Tzorakoleftherakis
il 8 Gen 2021
0 voti
My suspicion is that the error does not have much to do with the code you are showing but with how you create your environment. It seems you are using Simulink here - are you plotting anything in your Simulink model? Maybe trying to visualize what is happening with your system? That's what I would check first.
Jacob
il 6 Nov 2025
Spostato: Walter Roberson
il 16 Gen 2026
0 voti
I had the same error appear when trying to plot data that included NaNs. I had to restart matlab and get rid of the NaNs in my data. Then plot() worked.
Categorie
Scopri di più su Reinforcement Learning in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!