Output argument "varargout{2}" (and maybe others) not assigned during call error?

4 ビュー (過去 30 日間)
Chris Corbett
Chris Corbett 2012 年 10 月 29 日
Trying to plot contour lines with the associated gradient as arrows using the gradient function. My code is:
x = (-2:0.2:4);
y = (-2:0.2:2);
[x1 y1] = meshgrid(x,y);
h = (exp(-x1.^2-y1.^2))+0.5.*exp((-1.*(x1-2).^2)-y1.^2);
[C h]= contour (x,y,h);
hold all;
[hx,hy] = gradient(h);
quiver(x1, y1, hx, hy, 0.8)
I think I'm only getting one output from the gradient function, but shouldn't I be getting two?
Thanks, Chris.

回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 10 月 29 日
The problem is that you overwrite 'h' with the handle to the contourgroup so that h is no longer a two-dimensional matrix. Thus it cannot calculate the various components of the gradient and this error is thrown.
I agree that this error message could probably be better, I'll let our development team know.
  1 件のコメント
Chris Corbett
Chris Corbett 2012 年 10 月 29 日
Ah, yeah I see that now, quite obvious really.
Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by