超过1 ans怎么走吗

1视图(30天)
Pawel Pawel
Pawel Pawel 2022年3月11日
编辑: 约翰D 'Errico 2022年3月11日
你好,我是相当新的,使用matlab。我发现的问题,因为我想打印出三件事。当我使用功能只有1 ans。当我试图只使用Dsp我只使用名称和Dsp三件事我我不是杀敌变量的函数。我的尝试:
(5)统计数据
函数X =统计(num)
[A, b] = Fillthearray (num);
(L1, L2) =胆固醇(A, num);
disp (L1);
disp (L2);
disp (b)
函数(L1, L2, b) =统计(num)
[A, b] = Fillthearray (num);
(L1, L2) =胆固醇(A, num);
结束
在第二个metod我得到了输出:
ans =
0.0000 + 3.1623我0.0000 + 0.0000 0.0000 0.0000我0.0000 + 0.0000 + 0.0000 + 0.0000
0.0000 - 0.7906我0.0000 + 3.0619 0.0000 + 0.0000 0.0000 0.0000 + 0.0000 + 0.0000我
0.0000 + 0.0000我0.0000 - 0.8165 0.0000 3.0551 0.0000 + 0.0000 + 0.0000 + 0.0000我
0.0000 + 0.0000我0.0000 + 0.0000 0.0000 - 0.8183 0.0000 0.0000 + 0.0000 + 3.0546我
0.0000 + 0.0000我0.0000 + 0.0000 + 0.0000 0.0000 0.0000 - 0.8184我0.0000 + 3.0545
但我更喜欢得到3 ans (L1, L2, L3)

答案(2)

沃斯
沃斯 2022年3月11日
你需要指定其他输出变量以看到它们。所以在命令行上或在一个m文件你会这样说:
[my_L1, my_L2 my_b] =统计(5)
如果你不需要这些输出可以将变量替换为“~”,例如:
[~,~,my_b] =统计(5)
只会给你第三输出吗 统计数据()

约翰D 'Errico
约翰D 'Errico 2022年3月11日
编辑:约翰D 'Errico 2022年3月11日
要记住,函数返回多个参数是什么MATLAB与参数。考虑任何函数,它返回多个文稿。FZERO就是一个很好的例子。
帮助fzero
FZERO变量非线性零发现。X = FZERO(有趣,X0)试图找到一个函数的0 X0附近的乐趣,如果X0是一个标量。它首先找到一个区间包含X0区间端点的函数值不同的符号,然后搜索时间间隔为零。有趣的是一个函数处理。有趣的接受真正的标量输入X和返回一个真正的标量函数值F,评估在X FZERO返回的值X是附近一个有趣的变化标志(如果有趣的是连续的),或南如果搜索失败。X = FZERO(有趣,X0), X0是一个向量的长度2,假定X0是一个有限区间,有趣的符号(X0(1))不同于有趣的符号(X0 (2))。如果这不是真的发生错误。调用FZERO有限区间担保FZERO将返回一个值附近一个地方有趣的变化的迹象。X = FZERO(有趣,X0), X0是一个标量值,使用X0作为开始猜测。FZERO寻找一个区间,其中包含一个信号包含X0的乐趣和变化。 If no such interval is found, NaN is returned. In this case, the search terminates when the search interval is expanded until an Inf, NaN, or complex value is found. Note: if the option FunValCheck is 'on', then an error will occur if an NaN or complex value is found. X = FZERO(FUN,X0,OPTIONS) solves the equation with the default optimization parameters replaced by values in the structure OPTIONS, an argument created with the OPTIMSET function. See OPTIMSET for details. Used options are Display, TolX, FunValCheck, OutputFcn, and PlotFcns. X = FZERO(PROBLEM) finds the zero of a function defined in PROBLEM. PROBLEM is a structure with the function FUN in PROBLEM.objective, the start point in PROBLEM.x0, the options structure in PROBLEM.options, and solver name 'fzero' in PROBLEM.solver. [X,FVAL]= FZERO(FUN,...) returns the value of the function described in FUN, at X. [X,FVAL,EXITFLAG] = FZERO(...) returns an EXITFLAG that describes the exit condition. Possible values of EXITFLAG and the corresponding exit conditions are 1 FZERO found a zero X. -1 Algorithm terminated by output function. -3 NaN or Inf function value encountered during search for an interval containing a sign change. -4 Complex function value encountered during search for an interval containing a sign change. -5 FZERO may have converged to a singular point. -6 FZERO can not detect a change in sign of the function. [X,FVAL,EXITFLAG,OUTPUT] = FZERO(...) returns a structure OUTPUT with the number of function evaluations in OUTPUT.funcCount, the algorithm name in OUTPUT.algorithm, the number of iterations to find an interval (if needed) in OUTPUT.intervaliterations, the number of zero-finding iterations in OUTPUT.iterations, and the exit message in OUTPUT.message. Examples FUN can be specified using @: X = fzero(@sin,3) returns pi. X = fzero(@sin,3,optimset('Display','iter')) returns pi, uses the default tolerance and displays iteration information. FUN can be an anonymous function: X = fzero(@(x) sin(3*x),2) FUN can be a parameterized function. Use an anonymous function to capture the problem-dependent parameters: myfun = @(x,c) cos(c*x); % The parameterized function. c = 2; % The parameter. X = fzero(@(x) myfun(x,c),0.1) Limitations X = fzero(@(x) abs(x)+1, 1) returns NaN since this function does not change sign anywhere on the real axis (and does not have a zero as well). X = fzero(@tan,2) returns X near 1.5708 because the discontinuity of this function near the point X gives the appearance (numerically) that the function changes sign at X. See also ROOTS, FMINBND, FUNCTION_HANDLE. Documentation for fzero doc fzero
我们看到,fzero可以返回3输出。电话是这样的:
[X, FVAL EXITFLAG] = fzero (…)
但是如果你不使用所有三个吗?让我们试试,看看会发生什么。
有趣= @ (x) sin (x) - 0.5;
现在我知道这个函数将有一个根π/ 6。
格式长g
π/ 6
ans =
0.523598775598299
有趣(π/ 6)
ans =
-5.55111512312578 e-17
这已经非常明显,因为我们可以来一个根,对吧?现在fzero试试,看看会发生什么,如果我们只使用fzero,没有返回的参数呢?
[0,1],fzero(有趣)
ans =
0.523598775598299
它发现预期的解决方案,并返回根发现。但它与该值什么?它倾倒到一个名为ans的变量的结果。如果我们想保存结果,然后我们需要做的:
xroot = fzero(有趣,[0,1])
xroot =
0.523598775598299
现在我们看到变量xroot存在,并指示值。所以一切都好。但fzero也返回其他结果。如果我们希望他们,那么我们需要告诉MATLAB拯救他们。否则,MATLAB是转储到水桶,从未见过。所以我们可以这样做:
[xroot, fval exitflag] = fzero(有趣,[0,1])
xroot =
0.523598775598299
fval =
-5.55111512312578 e-17
exitflag =
1
现在我们看到三个变量已经创建并充满了期望的结果。如果由于某种原因,我们想只看到其中的一些结果,我们可以告诉MATLAB将不必要的入桶。我们使用~“论点”回电话。
[xroot ~, exitflag] = fzero(有趣,[0,1])
所以这最后叫存储结果xroot exitflag,但告诉MATLAB发送第二个返回到地狱。

下载188bet金宝搏


释放

R2022a

社区寻宝

找到宝藏在MATLAB中央,发现社区如何帮助你!

开始狩猎!