0

2 つの軸があります。1 つは画像を表示するためのもので、もう 1 つはグラフをプロットするためのものです。Error using plot. A numeric or double convertible argument is expectedデータをプロットする軸を指定しようとすると、このエラーが発生しますplot(handles.axis,curve,x,y)

figure
handles.axis = gca;
x = 1:10;
y = 1:10;
curve = fit(x',y','linearinterp');
plot(curve,x,y) % works fine
plot(handles.axis,curve,x,y) % doesn't work
plot(curve,x,y,'Parent',handles.axis)  % doesn't work

この例を Matlab に貼り付けて試すことができます。軸を指定するためにコードをどのように修正できますか?

4

2 に答える 2

1

plot曲線近似ツールボックスの は、 MATLAB の baseplotと同じではありません。オブジェクトの親軸を指定するための文書化された構文がありますが、この場合、呼び出しによって返されるオブジェクトの構文sfitはないようです。cfitfit

ただし、ドキュメントから次のことがわかります。

plot(cfit)cfit存在する場合、現在の座標軸のドメイン上にオブジェクトをプロットします

そのため、現在の軸plotが呼び出しの前に設定されている場合、希望どおりに機能するはずです。これは、Figure のCurrentAxesプロパティを変更するかaxes、axes オブジェクトのハンドルを入力として呼び出して実行できます。

% Set up GUI
h.f = figure;
h.ax(1) = axes('Parent', h.f, 'Units', 'Normalized', 'Position', [0.07 0.1 0.4 0.85]);
h.ax(2) = axes('Parent', h.f, 'Units', 'Normalized', 'Position', [0.55 0.1 0.4 0.85]);

% Set up curve fit
x = 1:10;
y = 1:10;
curve = fit(x', y', 'linearinterp');  % Returns cfit object

axes(h.ax(2));  % Set right axes as CurrentAxes
% h.f.CurrentAxes = h.ax(2);  % Set right axes as CurrentAxes
plot(curve, x, y);
于 2016-08-27T16:46:21.273 に答える
1

私は次のように答えを絞り込みます。

plot関数は、軸の後に 2 つのベクトルが続くフィット オブジェクトを好まないようです。そのような場合、私は次のようなことをします:

x = 1:10;
y = 1:10;
figure % new figure
ax1 = subplot(2,1,1);
ax2 = subplot(2,1,2);

curve = fit(x',y','linearinterp');
plot(ax1,x,curve(x));
hold on;plot(ax1,x,y,'o') % works fine

plot(ax2,x,curve(x));
hold on;plot(ax2,x,y,'o') % works fine

実際には、フィット オブジェクト全体を関数に渡さずに 2 つのベクトルとしてx提供するのがコツです。curve(x)plot

于 2016-08-27T18:39:53.070 に答える