I want to plot latitude and longitude data together with another type of data (speed), recorded at every latitude-longitude-point. This is basically equivalent to
figure()
subplot(1,2,1); plot(lat,lon);
subplot(1,2,2); plot(t,y);
Where all vectors have the same length and t
is the timestamp in seconds for every recording. I'd love to be able to link the data such that when I highlight data in the first subplot, the corresponding data gets highlighted in the second subplot (and vice versa).
However, because the two subplots don't have a common data source (at least not by name), I struggle to get linkdata
working.
Here's what I tried (without linkdata
)
function linkedexasmple()
close all
t = linspace(-2,2,100);
lat = sin(t);
lon = cos(t);
x = t;
y = exp(t);
M = [lat',lon',x',y'];
figure()
whos
subplot(1,2,1)
plot(M(:,1),M(:,2),'-x','XDataSource','M(:,1)','YDataSource','M(:,2)');
subplot(1,2,2)
plot(M(:,3),M(:,4),'-x','XDataSource','M(:,3)','YDataSource','M(:,4)');
%linkdata on
%linkdata showdialog
end
However, if I toggle linkdata on
, the plot completely changes to this.
How can I preserve the original plot while enabling linking them?
As a last remark: I would obviously want to call that function with arguments (lat
, lon
, x
, y
) later on. But for this MWE, I thought it would be easier this way.