- First load the data in MATLAB and extract desired columns using indexing.
- Use plot function to plot the magnetic field vs time, where the color of the line determined by the label.
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.
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:
for i = 0:5
idx = find(label == i);
plot(time(idx), mag(idx), 'Color', rand(1,3), 'DisplayName', ['Label ' num2str(i)]);
3. Now implement a callback function “WindowButtonDownFcn” and plot the 2nd plot inside this function.
f = figure(WindowButtonDownFcn=@figureCallback);
%% enter you code here to plot the 2nd plot
line = findobj(src,"Type","Line");
line.Color = "red";
Refer MATLAB documentation page :