gpt4 book ai didi

matlab - 矩阵作为函数的输出

转载 作者:太空宇宙 更新时间:2023-11-03 19:47:18 25 4
gpt4 key购买 nike

也许是一个非常简单的问题,但我已经在互联网上寻找了几个小时的答案,但我找不到。

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

任何人都可以告诉我我必须更改什么,以便我可以读取矩阵的各个单元格吗?

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

最佳答案

正如您所定义的,您的函数 Actual_Location 编写的矩阵的 m 文件中的名称是 actual_location。然而,当你调用你的函数时,你可以给输出任何你喜欢的名字。我猜你是这样调用它的,记住 Matlab 有点区分大小写:

actual_location = Actual_Location(arguments);

你只是在写作来迷惑自己。在函数定义中为伪参数使用 actual_location 以外的名称,并调用函数以返回具有更不同名称的变量,如下所示:

output = Actual_Location(arguments);

看起来您可能期望 actual_location(1,1) 返回数组的元素 1,1,而它可能是具有 2 个输入参数的函数调用。

关于matlab - 矩阵作为函数的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2178638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com