matlab学习计划11.4

来源:互联网 发布:7.1声道耳机推荐 知乎 编辑:程序博客网 时间:2024/05/16 01:21

1.minmax用于计算向量的max/min,因此事实上range函数可以用maxmin间接实现。maxmin主要在神经网络中用到,也可以在其他场合使用:

Y=minmax(X)

Minmax函数默认针对==行向量==进行计算。so,如果X是(m**n)矩阵,Y返回一个m***2的矩阵,每行元素对应max/min。X还可以十一矩阵为元素组成的cellArray.

>> rng(2,'v4')>> a=rand(3,4)a =    0.0258    0.1901    0.2319    0.0673    0.9210    0.8673    0.1562    0.3843    0.7008    0.4185    0.7385    0.9427>> minmax(a)ans =    0.0258    0.2319    0.1562    0.9210    0.4185    0.9427>> x=nndata([1;2],3,4)x =     [1x3 double]    [1x3 double]    [1x3 double]    [1x3 double]    [2x3 double]    [2x3 double]    [2x3 double]    [2x3 double]>> mm=minmax(x)%计算细胞数字的max/minmm =     [1x2 double]    [2x2 double]>> mm{1}ans =    0.0167    0.8921>> mm{2}ans =    0.0222    0.8808    0.0840    0.8560

2.nndata函数:创建神经网路数据

function x = nndata(elements,samples,timesteps,value)%NNDATA Create neural network data.%%  <a href="matlab:doc nndata">nndata</a> creates data in the cell array data format used by%  Neural Network Toolbox software.%%  Neural network cell data consists of a cell array which has as many rows%  as there are signals and as many columns as there are timesteps.%  Each element {i,j} of the cell array is a matrix which has as many rows%  as the ith signal has elements and as many columns as there are samples.  %%  <a href="matlab:doc nndata">nndata</a>(N,Q,TS) returns random neural network data in cell array form.%  It takes an M-element row vector N of element sizes for M signals,%  the number of samples Q and number of timesteps TS.  If any of these%  arguments are not provided their default value is 1.%%  The returned value is an MxTS cell array where each {i,ts} element%  is an N(i)xQ matrix.%%  <a href="matlab:doc nndata">nndata</a>(N,Q,TS,V) returns neural network data consisting of the scalar%  value V.%%  Here four samples of five timesteps, for a 2-element signal consisting%  of zero values is created:%%    x = <a href="matlab:doc nndata">nndata</a>(2,4,5,0)%%  To create random data with the same dimensions:%%    x = <a href="matlab:doc nndata">nndata</a>(2,4,5)%%  Here static (1 timestep) data of 12 samples of 4 elements is created.%%    x = <a href="matlab:doc nndata">nndata</a>(4,12)%%  You can access subsets of neural network data with <a href="matlab:doc getelements">getelements</a>,%  <a href="matlab:doc getsamples">getsamples</a>, <a href="matlab:doc gettimesteps">gettimesteps</a>, and <a href="matlab:doc getsignals">getsignals</a>.%%  You can set subsets of neural network data with <a href="matlab:doc setelements">setelements</a>,%  <a href="matlab:doc setsamples">setsamples</a>, <a href="matlab:doc settimesteps">settimesteps</a>, and <a href="matlab:doc setsignals">setsignals</a>.%%  You can concatenate subsets of neural network data with <a href="matlab:doc catelements">catelements</a>,%  <a href="matlab:doc catsamples">catsamples</a>, <a href="matlab:doc cattimesteps">cattimesteps</a>, and <a href="matlab:doc catsignals">catsignals</a>.%%  See also TONNDATA, FROMNNDATA, NNSIZE.% Copyright 2010-2012 The MathWorks, Inc.if nargin < 1, elements = 1; endif nargin < 2, samples = 1; endif nargin < 3, timesteps = 1; endnntype.pos_int_vector('check',elements,'Number of elements');nntype.pos_int_scalar('check',samples,'Number of samples');nntype.pos_int_scalar('check',timesteps,'Number of timesteps');signals = length(elements);if (nargin < 4) || isempty(value)  x = cell(signals,timesteps);  for i=1:signals    for j=1:timesteps      x{i,j} = rand(elements(i),samples);    end  endelse  x = cell(signals,1);  for i=1:signals    x{i,1} = value + zeros(elements(i),samples);  end  x = x(:,ones(1,timesteps));end
NNDATA创建神经网络数据。<a href="matlab:doc nndata"> nndata </a>以所使用的单元格数组数据格式创建数据神经网络工具箱软件。神经网络单元数据由具有尽可能多的行的单元阵列组成,因为有信号和与时间步长一样多的列。单元阵列的每个元素{i,j}是具有尽可能多的行的矩阵,因为第i个信号具有元素和与样本一样多的列。<a href="matlab:doc nndata"> nndata </a>(N,Q,TS)返回单元格数组形式的随机神经网络数据。它获取M个信号的元素尺寸的M元素行向量N,的样本数Q和时间步数TS。如果有这些不提供%参数,它们的默认值为1。==返回的值是一个MxTS单元格数组,其中每个{i,ts}元素是N(i)×Q矩阵。==<a href="matlab:doc nndata"> nndata</a>(N,Q,TS,V)返回由标量组成的神经网络数据值V.这里有四个样本的五个时间步长,用于2元素信号组成创建零值的百分比:x = <a href="matlab:doc nndata">数据</a>(2,4,5,0)创建具有相同尺寸的随机数据:x = <a href="matlab:doc nndata"> nndata </a>(2,4,5)这里创建4个元素的12个样本的静态(1个时间步长)数据。x = <a href="matlab:doc nndata"> nndata </a>(4,12)您可以使用<a href="matlab:doc getelements">getelements </a>访问神经网络数据子集,<a href="matlab:doc getsamples">取样</a><a href="matlab:doc gettimesteps"> gettimesteps </a><a href="matlab:doc getsignals">获取信息</ a>。您可以使用<a href="matlab:doc setelements">setelements </a>设置神经网络数据子集,<a href="matlab:doc setsamples">样本</a><a href="matlab:doc settimesteps">设置步距</a><a href="matlab:doc setsignals"> setsignals </ a>。您可以使用<a href="matlab:doccatelements">资源</a>连接神经网络数据子集,<a href="matlab:doc catsamples"> catsamples </a><a href="matlab:doc cattimesteps"> cattimesteps </a><a href="matlab:doc catsignals"> catsignals </ span> a>。另见TONNDATA,FROMNNDATA,NNSIZE。版权所有2010-2012 The MathWorks,Inc.

3.max/min/mean函数:

  • max

句法:
1. M = max(A)

  1. M = max(A,[],dim)

  2. [M,I] = max(_)

  3. C = max(A,B)

Description

example

M = max(A) returns the largest elements of A.

  • If A is a vector, then max(A) returns the largest element of A.

  • If A is a matrix, then max(A) treats the columns of A as vectors and returns a row vector of largest elements.(在列向量里面找到max,然后列成行向量)

  • If A is a multidimensional array, then max(A) treats the values along the first array dimension whose size does not equal 1 as vectors and returns an array of maximum values. The size of this dimension becomes 1 while the sizes of all other dimensions remain the same.(则max(A)将大小不等于1的第一个数组维度的值视为向量,并返回最大值数组。此维度的大小变为1,而所有其他维度的大小保持不变。)

==example==
- M = max(A,[],dim) returns the largest elements along dimension dim. For example, if A is a matrix, then max(A,[],2) is a column vector containing the maximum value of each row.(包含每行的最大值的列向量)

==example==

  • [M,I] = max(_) finds the indices of the maximum values of A and returns them in output vector I, using any of the input arguments in the previous syntaxes. If there are several identical maximum values, then max returns the index of the first one.
    (返回max在X中的位置索引,若多个相同则返回第一个值的位置)
    ==example==

  • C = max(A,B) returns an array the same size as A and B with the largest elements taken from A or B. The dimensions of A and B must match, or one can be a scalar.(比较A和B相同位置元素的大小,返回是一个m*n的矩阵(A和B是同型矩阵),若B为标量,则标量扩展成与A同型的矩阵)

min函数基本原理和max函数相同;

mean:平均值

句法:

  • M = mean(A)

  • M = mean(A,dim)

  • M = mean(_,type)

Description

example

==M = mean(A)== returns the mean value along the first array dimension of A whose size does not equal 1.(例如非空非向量矩阵则返回列向量的平均值组成的行向量)

  • If A is a vector, then mean(A) returns the mean of the elements.

  • If A is a nonempty, nonvector matrix, then mean(A) treats the columns of A as vectors and returns a row vector whose elements are the mean of each column.

  • If A is an empty 0-by-0 matrix, then mean(A) returns NaN.

  • If A is a multidimensional array, then mean(A) treats the values along the first array dimension whose size does not equal 1 as vectors and returns an array of row vectors. The size of this dimension becomes 1 while the sizes of all other dimensions remain the same.

==example==

  • M = mean(A,dim) returns the mean along dimension dim. For example, if A is a matrix, then mean(A,2) is a column vector containing the mean of each row.

==example==

- M = mean(_,type) returns the mean in the class specified by type, using any of the input arguments in the previous syntaxes. type can be ‘double’, ‘native’, or ‘default’.

The type option does not support datetime arrays or duration arrays. A or B. The dimensions of A and B must match, or one can be a scalar.

 b=randn(4)b =    1.0644    1.0075   -0.8900   -0.9547    1.5076    0.5383   -1.9832   -0.7598    1.8966   -0.6168    0.9503    0.3192    1.2472   -1.2161    0.3468    0.6004>> max(b)ans =    1.8966    1.0075    0.9503    0.6004>> min(b)ans =    1.0644   -1.2161   -1.9832   -0.9547>> mean(b)ans =    1.4290   -0.0718   -0.3940   -0.1987>> mean(b,1)ans =    1.4290   -0.0718   -0.3940   -0.1987>> mean(b,2)ans =    0.0568   -0.1743    0.6373    0.2446>> max(b,1)ans =    1.0644    1.0075    1.0000    1.0000    1.5076    1.0000    1.0000    1.0000    1.8966    1.0000    1.0000    1.0000    1.2472    1.0000    1.0000    1.0000>> max(b,[],1)ans =    1.8966    1.0075    0.9503    0.6004>> max(b,[],2)ans =    1.0644    1.5076    1.8966    1.2472>> min(b,[],1)ans =    1.0644   -1.2161   -1.9832   -0.9547>> min(b,[],2)ans =   -0.9547   -1.9832   -0.6168   -1.2161>> [Y,I]=min(b)Y =    1.0644   -1.2161   -1.9832   -0.9547I =     1     4     2     1>> [Y,I]=max(b)Y =    1.8966    1.0075    0.9503    0.6004I =     3     1     3     4>> Y=max(b,2)Y =     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2>> c=randi(4)c =     4>> c=randi(1,4)c =     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1>> max(b,c)ans =    1.0644    1.0075    1.0000    1.0000    1.5076    1.0000    1.0000    1.0000    1.8966    1.0000    1.0000    1.0000    1.2472    1.0000    1.0000    1.0000
0 0
原创粉丝点击