MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   矩阵作为函数的输出 (https://www.labfans.com/bbs/showthread.php?t=23092)

poster 2019-12-10 20:30

矩阵作为函数的输出
 
也许这是一个非常简单的问题,但是我已经在互联网上寻找答案了几个小时,但找不到。

我已经创建了下面的函数。在另一个m文件中,我想使用矩阵“ actual_location”。但是,不可能使用矩阵的单个单元格(即actual_location(3,45)或actual_location(1,2))。当我尝试使用单个单元格时,出现以下错误: ??? Error using ==> Actual_Location Too many input arguments.

谁能告诉我我必须更改什么,以便我可以读取矩阵的各个单元格?

function [actual_location] = Actual_Location(~); actual_location=zeros(11,161); for b=1:11 for t=1:161 actual_location(b,t) = (59/50)*(t-2-(b-1)*12)+1; if actual_location(b,t) < 1 actual_location(b,t) =1; end end actual_location(1,1) end

[B]回答:[/B]

定义好后,由函数Actual_Location编写的矩阵在m文件中的名称为Actual_location。但是,当您调用函数时,可以给输出任何您喜欢的名称。我想您是这样称呼的,记住Matlab区分大小写:

actual_location = Actual_Location(arguments); 您只是为了混淆自己而写作。对于函数定义中的哑元参数,使用不同于Actual_location的名称,然后调用函数以返回具有更独特名称的变量,如下所示:

output = Actual_Location(arguments); 似乎您可能期望Actual_location(1,1)返回数组的元素1,1,而它可能是带有2个输入参数的函数调用。



[url=https://stackoverflow.com/questions/2178638]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 04:55

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.