简体   繁体   English

如何绘制Octave \\ Matlab函数输出?

[英]How can I plot this Octave\Matlab function output?

I everyone, I am pretty new in Octave\\MatLab and I have the following doubt. 我是大家,我在Octave \\ MatLab中很新,我有以下疑问。 I have this code calculating a sigmoid function for a parameter z: 我有这个代码计算参数z的sigmoid函数:

function g = sigmoid(z)
%SIGMOID Compute sigmoid function
%   g = SIGMOID(z) computes the sigmoid of z.

% You need to return the following variables correctly 
g = zeros(size(z));

% ====================== YOUR CODE HERE ======================
% Instructions: Compute the sigmoid of each value of z (z can be a matrix,
%               vector or scalar).

g = 1 ./ (1 + exp(-z));

% =============================================================

end

z could be a scalar, a vector or a matrix. z可以是标量,向量或矩阵。

For example doing something like this: 例如,做这样的事情:

>> X = [1 2; 0 5]
X =

   1   2
   0   5

>> g = 1 ./ (1 + exp(-X));
>> g
g =

   0.73106   0.88080
   0.50000   0.99331

Given the matrix X having 2 features X1 and X2 (the 2 column) how can I plot this function? 鉴于矩阵X具有2个特征X1和X2(2列),我如何绘制此函数? The output is a three dimensional function? 输出是三维函数?

The output is not a 3D function because you have one input X , and one output g , it's 2D. 输出不是3D功能,因为您有一个输入X和一个输出g ,它是2D。

You can display it column by column , displaying each column as a separate function on the same plot: 您可以逐列显示它,在同一个图上将每列显示为单独的函数:

plot(X, g)

which is equivalent to: 这相当于:

figure
hold on
for i = 1:size(X,2)
    plot(X(:,i), g(:,i))
end
hold off

You can display it row by row , displaying each row as a separate function on the same plot: 您可以逐行显示它,在同一个图上将每一行显示为单独的函数:

plot(X', g')

which is equivalent to: 这相当于:

figure
hold on
for i = 1:size(X,1)
    plot(X(i,:), g(i,:))
end
hold off

You can display it as an array : 您可以将其显示为数组

plot(X(:), g(:))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM