- 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
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Sachin
2023-6-5
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:
%
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!