Displaying magnetic data line in different colors and updating subplot by clicking on it

1 visualización (últimos 30 días)
I have some magnetic data with labels. The array contains time, magnetic feild, label, x-magnetic feild, y-magnetic feild, z-magnetic feild. The column label has values: 0, 1, 2, 3, 4 or 5. I want to plot 2 plots. The first has magnetic feild vs time but the color of the line should be different as per the labels. On clicking at any point on the first plot, I want to update the 2nd plot using x-magnetic feild, y-magnetic feild, z-magnetic feild values. Can you please help me achieve this?
Thanks in advance.

Respuestas (1)

Sachin el 5 de Jun. de 2023
I understand that you want to plot 2 plots with different colors and want to update the subplot by clicking on it.
Following workaround might be helpful to you:
  1. First load the data in MATLAB and extract desired columns using indexing.
  2. Use plot function to plot the magnetic field vs time, where the color of the line determined by the label.
hold on;
for i = 0:5
idx = find(label == i);
plot(time(idx), mag(idx), 'Color', rand(1,3), 'DisplayName', ['Label ' num2str(i)]);
ylabel('Magnetic Field');
3. Now implement a callback function “WindowButtonDownFcn” and plot the 2nd plot inside this function.
f = figure(WindowButtonDownFcn=@figureCallback);
function figureCallback(src,event)
%% enter you code here to plot the 2nd plot
line = findobj(src,"Type","Line");
line.Color = "red";
Refer MATLAB documentation page :


Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by