Linkdata not refreshing graph

5 vues (au cours des 30 derniers jours)
Alex
Alex le 28 Août 2024
Commenté : Alex le 29 Août 2024
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'
Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='.
%% 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?

Réponse acceptée

Steven Lord
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."
  1 commentaire
Alex
Alex le 29 Août 2024
Yes! This was the answer - the data was not correctly linked and so wasnt accepting the updates. Looking at the documentation for this it only seems to be able to do one data source per axis, is there a way to have multiple lines be linked?
ax1_Plot.XDataSource = 'Display_timebase';
ax1_Plot.YDataSource = 'Display_Power_cmd';
somethink akin to
ax1_Plot.YDataSource2 = 'Display_Power_cmd';

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by