Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I (think) I see what you are trying to achieve. You are writing your syntax like a mathematical function definition. Matlab is interpreting <code>f</code> as a 2-dimensional data type and trying to assign the value of the expression to data indexed at <code>x,y</code>. The values of <code>x</code> and <code>y</code> are not integers, so Matlab complains.</p> <p>If you want to plot the output of the function (we'll call it <code>z</code>) as a function of <code>x</code> and <code>y</code>, you need to define the function quite differently . . . </p> <pre><code>f = @(x,y)(x-3).^2 - (y-2).^2; x=2:.2:4; y=1:.2:3; z = f( repmat(x(:)',numel(y),1) , repmat(y(:),1,numel(x) ) ); surf(x,y,z); xlabel('X'); ylabel('Y'); zlabel('Z'); </code></pre> <p>This will give you an output like this . . . <img src="https://i.stack.imgur.com/sfMjY.png" alt="enter image description here"></p> <p>The <code>f = @(x,y)</code> part of the first line states you want to define a function called <code>f</code> taking variables <code>x</code> and <code>y</code>. The rest of the line is the definition of that function.</p> <p>If you want to plot <code>z</code> as a function of both <code>x</code> and <code>y</code>, then you need to supply all possible combinations in your range. This is what the line containing the <code>repmat</code> commands is for.</p> <p><strong>EDIT</strong></p> <p>There is a neat Matlab function <code>meshgrid</code> that can replace the repmat version of the script as suggested by @bas (welcome bas, please scroll to bas' answer and +1 it!) ...</p> <pre><code>f = @(x,y)(x-3).^2 - (y-2).^2; x=2:.2:4; y=1:.2:3; [X,Y] = meshgrid(x,y); surf(x,y,f(X,Y)); xlabel('x'); ylabel('y'); zlabel('z'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload