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

4 Ansichten (letzte 30 Tage)
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.

Antworten (1)

Sachin
Sachin am 5 Jun. 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.
%
figure;
hold on;
for i = 0:5
idx = find(label == i);
plot(time(idx), mag(idx), 'Color', rand(1,3), 'DisplayName', ['Label ' num2str(i)]);
end
xlabel('Time');
ylabel('Magnetic Field');
legend('show');
3. Now implement a callback function “WindowButtonDownFcn” and plot the 2nd plot inside this function.
f = figure(WindowButtonDownFcn=@figureCallback);
plot(1:10)
function figureCallback(src,event)
%% enter you code here to plot the 2nd plot
line = findobj(src,"Type","Line");
line.Color = "red";
end
Refer MATLAB documentation page :
Thanks

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by