1

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

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Holy Moly, That's so simple ;D Thanks! I got what I wanted
0

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

2 Comments

I didn't know Octave could generate gnuplot scripts. Will try this out and get back
While I was able to generate the plot and the gnuplot script, I need the proper gnuplot code in order to integrate it with an existing script. The code generated this way isn't proper code so I can't accept this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.