Linkdata not refreshing graph
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have code for a battery controler i'm making, and as part of that i want to display some live results as it continues running. The whole system runs in a repreating while loop which you can see below(have removed some code to make it legible).
while On = 'true'
%% Initialise Display
Display = figure('Name','Controler Display','NumberTitle','off');
tiledlayout(2,1)
ax1 = nexttile;
plot(ax1,Display_timebase,Display_Power_cmd, "DisplayName","ESS Power Command (kW)")
title 'ESS input/output'
hold on
plot(ax1,Display_timebase,Display_Grid_Demand,"DisplayName","Grid Demand")
plot(ax1,Display_timebase,Display_Available_Power, "DisplayName","Available Power (kW)")
ylim([-300 320])
legend
xline(0)
hold off
ylabel("ESS Power in/output")
xlabel("Time")
xlim([-12 48])
ax2 = nexttile;
plot(ax2,Display_timebase,Display_ESS_SoC)
title 'SoC over time'
ylim([0 1.05])
ylabel("ESS SoC")
xlabel("Time")
xlim([-12 48])
xline(0)
linkdata(Display,'on')
drawnow
%%%%%%%%%%%
%% Additional Code
%%%%%%%%%%%
%% Update Display values
Display_Power_cmd = [Historical_power_cmd Navigator_Outputs.Power_cmd'];
Display_Grid_Demand = [Historical_Grid_Demand Navigator_Outputs.Grid_Demand'];
Display_Available_Power = [Historical_Available_Power Mapper_Outputs.Available_Power'];
Display_ESS_SoC = [Historical_SoC ESS_SoC_array'];
drawnow
end
I'm aware that being in a while loop suppresses figure updates, hence why i've included the drawnows but my figures still refuse to update. What am i doing wrong here?
0 commentaires
Réponse acceptée
Steven Lord
le 28 Août 2024
As written, this is going to recreate the figure and the plots each time through the while loop. Do you want to move those ahead of the while loop and only update the variables in the loop?
Can you check that the data linkage was established correctly? From the first entry in the Tips section on the linkdata documentation page, "If linkdata cannot unambiguously identify data sources for a chart, then the chart will not synchronize with workspace variables. If you call linkdata and your chart does not update when you change a variable, then open the Linked Plot Data Sources dialog box by calling linkdata showdialog and manually link the chart to its data sources."
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!