Plotting a 1D function by hovering on a 2D plot
Ältere Kommentare anzeigen
Let's say I have a 2D surface plot of function x and y. So z is a function of x and y. I also have a variavle F which is a function of x, y and v. What I want to do is to have a tool where I hover on the 2D plot (x, y, z) and based on the x and y co-ordinates, it should update another 1D plot that is F vs v at that (x, y).
How to make this tool?
clear;
close all;
[x, y] = meshgrid(linspace(1, 100, 100), linspace(1, 100, 100));
z = rand(100, 100);
figure; surface(x, y, z); shading flat; colorbar; % I want to hover on this plot
% example of the 1D plot
v = linspace(-15, 15, 128);
for i = 1:100
for k = 1:100
F(i, k, :) = rand(1, 128);
end
end
x_indx = 30;
y_indx = 40;
F_squeeze = squeeze(F(x_indx, y_indx, :));
figure; plot(v, F_squeeze);
Akzeptierte Antwort
Weitere Antworten (1)
John D'Errico
am 19 Okt. 2022
0 Stimmen
We all want things we cannot easily have. For example, I would very much want to see world peace. Will I ever see it? Probably not, as much as I might want it. Lacking that, how about a nice red Lamborghini for X-mas? Not gonna happen either. ;-)
Seriously, there is no tool that will do what you want in MATLAB. However, you could probably write it, with some degree of effort. You would need to set up callbacks on the plot, so that when you click on it, your code will see where you clicked, and recover the (x,y) coordinates for that point. Then it will evaluate the desired function F, and plot F, as a function of (x,y,v), with x and y fixed as a new 1-d plot. So doable. But not as anything that exists directly off the shelf. If you want it badly enough, you just need to write the code. It would require a mouse click though. I think hovering will not be sufficient.
And, yes, if I really wanted that Lambo badly enough, I could buy it. But, I'm pretty sure a Lambo gets terrible traction in a foot of snow up where I live.
1 Kommentar
Tworit Dash
am 19 Okt. 2022
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

