Reputation: 143
I have the following 3d plot in MATLAB that I'm trying to plot in Gnuplot but don't know how to. In MATLAB, the x,y,z are matrices that are calculated inside a nested for loop, then plotted:
w = 50 ;
ww = 0:1:w ;
d = 100 ;
dd = 0:1:d ;
for i=1:1:length(ww)
for j=1:1:length(dd)
x(i,j) = dd(i) ; % need to refer to array dd
y(i,j) = dd(j) ;
z(i,j) = <A complicated function ommitted for simplicity>
end
end
plot3(x,y,z)
How would I plot the above in Gnuplot? I need to do it for arbitrary values of w
and d
. I understand that I need the splot
function but I am at a loss as to how to implement the calculation of the x,y,z matrices. Help will be appreciated!
Edit: It seems like the above can be done using the array
and word
keywords/function but I haven't been able to implement it yet
Upvotes: 1
Views: 334
Reputation: 48390
In gnuplot, simply set your ranges and plot the function:
set xrange [0:50]
set yrange [0:100]
z(x,y) = exp(-(x**2 + y**2)/100.0)
splot z(x, y)
If you want to change the grid, use set isosamples
to do that, like
set isosamples 51,101
Upvotes: 1
Reputation: 5220
You could somewhat cheat, and create the gnuplot plot file from GNU Octave https://www.gnu.org/software/octave/
Assuking you have Octave installed:
Set the graphics toolkit in octave to gnuplot:
graphics_toolkit gnuplot
Then run your p[lot script.
Then dump it to a gnuplot file (assuming running in linux - in windows the x11 and /dev/null would need to change):
drawnow ("x11", "/dev/null", false, "gnuplot.gpt")
There should now be a file gnuplot.gpt that can be loaded by gnuplot - console command:
gnuplot -p gnuplot.gpt
Upvotes: 0