[Matlab R2024b] [SDI] How to assign data to SDI-Subplot(map-type) programmatically?

2 visualizzazioni (ultimi 30 giorni)
Is there a way to assign latitude and longitude values/signals programmatically which are already available in SDI? Is it possible per SDI API?
assume that the below 2 signals are available already in SDI.
  • trace_latitude
  • trace_longitude
I tried the following:
Simulink.sdi.clearPreferences;
Simulink.sdi.setSubPlotLayout(3,1);
Simulink.sdi.setVisualization(3,1,'map');
sigLatitude = getSignalsByName(mySDI,'trace_latitude');
sigLongitude = getSignalsByName(mySDI,'trace_longitude');
try
sigLatitude.plotOnSubPlot(3,1,true)
sigLongitude.plotOnSubPlot(3,1,true)
catch ME
fprintf('Message : %s\n', ME.message);
fprintf('Identifier : %s\n', ME.identifier);
end
output:
Message : Unable to plot signal trace_latitude on Map visualization.
Identifier : SDI:sdi:InvalidArguments

Risposte (2)

Malte
Malte il 5 Ago 2025
I have the same question and can not make it work programmatically either. As a workaround I connect the latitude and longitude signals manually to an SDI with a map on top and save the view. Then i load the view programmatically. This works for me until we get a solution. I hope it helps you, too!

Ruchika Parag
Ruchika Parag il 1 Lug 2025
Hi @Mustafa Eren, the error message you are seeing occurs because the Simulation Data Inspector (SDI) map visualization requires a specific format for input signals. More precisely, the map plot expects a single signal that contains two columns of data—where the first column represents latitude and the second represents longitude. If latitude and longitude are provided as two separate scalar signals, the SDI map visualization will not be able to interpret them as a trajectory, and plotting will fail.
This behavior is by design. The SDI API does not currently support combining multiple scalar signals for use in a map visualization. Instead, it expects the route information to be supplied through one multi-dimensional signal that directly pairs each latitude value with its corresponding longitude value.
To resolve this, the latitude and longitude signals should be programmatically combined into a single 2-column signal. This can be done by extracting the signal data and time vectors from the original SDI run, combining the latitude and longitude values into a new matrix, and then creating a new run or variable that contains the combined route data. Once this is done, the new signal can be plotted on the map using the appropriate SDI settings.
Here is an example of how to implement this approach:
% Get the latest run
runs = Simulink.sdi.getAllRuns;
run = runs(end); % Adjust if needed
% Extract the latitude and longitude signals
latSig = run.getSignalByName('trace_latitude');
lonSig = run.getSignalByName('trace_longitude');
% Combine the data into a single [latitude, longitude] array
t = latSig.Values.Time;
data = [latSig.Values.Data, lonSig.Values.Data];
% Create a new SDI run with the combined signal
newRun = Simulink.sdi.createRun('Combined Route');
Simulink.sdi.addSignal(newRun, 'routeLatLon', t, data);
% Configure the map subplot and plot the new signal
Simulink.sdi.clearPreferences;
Simulink.sdi.setSubPlotLayout(1,1);
Simulink.sdi.setVisualization(1,1,'map');
routeSig = newRun.getSignalByName('routeLatLon');
routeSig.plotOnSubPlot(1,1,true);
Simulink.sdi.view;
In summary, SDI map plots require a single signal that encapsulates both latitude and longitude as a two-column data matrix. Separate scalar signals are not accepted for map display. The best approach is to prepare a combined route signal before attempting to visualize it. If the signals are already logged in SDI, this can be done by extracting and combining them in code as shown above. This will ensure the data is in a format the SDI map visualization expects and can work with effectively. Hope this helps!
  1 Commento
Mustafa Eren
Mustafa Eren il 4 Lug 2025
Thank you for the detailed explanation Ruchika.
It returns that there is no such function 'Simulink.sdi.addSignal'. do you have another suggestion for that?

Accedi per commentare.

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by