MATLAB函数将矩阵作为输入和返回元素在其四个角中作为输出

265意见(过去30天)
amos agbetile.
amos agbetile. 2019年2月6日
你好,大家好,我在写一个函数时遇到了困难,它取一个矩阵的输入,并返回它的角中的元素作为输出。
这是我的代码:
功能[top_left, top_right bottom_left bottom_right] =(我、r、c)角落
=矩阵(i r c)
top_left = a(1,1);
top_right = a(1,c);
bottom_left = a(r,1);
bottom_right = a(r,c);
功能b =矩阵(i,r,c)
ind = i;
行= r;
坳= c;
b = randi(ind,行,col);
我一直到来 没有足够的输入参数。
边角误差(直线2)
=矩阵(i r c)
谢谢你的回复。谢谢。
5点评论
乔纳森•迪帕克
乔纳森•迪帕克 2020年10月1日
你也可以这样使用这个函数
功能[a, b, c, d] =角落(左)
a = l(1,1);
B = L(1,结束);
c = l(结束,1);
d = l(结束,结束);
结尾

登录评论。

接受的答案

马特·J
马特·J 2019年2月7日
编辑:马特·J 2019年2月7日
也许这就是你真正想要的:
功能acorners =角落(a)
acorners = a([1,end],[1,end]);
结尾
7评论
马特·J
马特·J 于2020年9月19日
它得到了角落。你试过了吗?
>> A =南(5);A(:) = 1:25
A =
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
>> a([1,end],[1,结束])
ans =.
1 21.
5 25.

登录评论。

更多的答案(6)

Mayank Ghugretkar.
Mayank Ghugretkar. 2019年6月3日
功能[top_left,top_right,bottom_left,bottom_right] =角落(m)
top_left = M (1, 1);
top_right = M(1、结束);
bottom_left = M(结束,1);
bottom_right = m(结束,结束);
结尾
以下是要调用的代码:
a = randi(100,4,5)
[top_left,top_right,bottel_left,bottom_right] =角落(a)
B = [1;2]
[top_left,top_right,bottom_left,bottom_right] =角落(b)
我认为这将是更简单的批准..
3评论

登录评论。


马特·J
马特·J 2019年2月6日
编辑:马特·J 2019年2月6日
例如,当我运行代码时,我没有任何错误,例如,
[top_left,top_right,bottom_left,bottom_right] =角(10,10,10)
给了
top_left =.
4.
top_right =
7.
bottom_left =
7.
bottom_right =
4.
我能想到的唯一原因是你有另一个职能 矩阵() 在你的道路上,隐藏着你真正想要的。试,
>>哪个 - 所有矩阵
4评论
amos agbetile.
amos agbetile. 2019年2月7日
是的,谢谢。我想这就是问题所在。我应该使用这个函数在命令窗口中运行以下代码行:
a = randi(100,4,5)
[top_left,top_right,bottel_left,bottom_right] =角落(a)
a = [1;2]
[top_left,top_right,bottom_left,bottom_right] =角落(b)
有什么建议吗?
谢谢。

登录评论。


的大作
的大作 2019年2月6日
编辑:的大作 2019年2月6日
我不认为这条线有什么特别的问题。
问题可能在调用它时,您可能没有向Corners发送输入或足够的输入。
尝试从命令窗口用有效值调用角,或者当你使用运行按钮T顶部或使用F5运行时,你可以在运行按钮菜单指定输入

哈里亚
哈里亚 2019年6月16日
功能[top_left, top_right bottom_left bottom_right] =角落(A)
top_left = a(1,1)
top_right = a(1,端)
bottom_left = (, 1)
bottom_right =(结束,结束)
结尾
4评论
斯蒂芬Cobeldick.
斯蒂芬Cobeldick. 2020年6月7日
“但是我也定义了top_right, bottom_left和bottom_right作为输出参数。”
您在函数中定义了它们,但在调用函数时,您没有使用任何输出参数。
如何调用函数(具有多个输出参数)在史蒂文领主评论中解释在上面以及介绍性教程中:

登录评论。


和el houda bouhaddoun
谁能帮帮我,因为我不知道问题在哪里
函数[top_left,top_right,bottel_left,bottom_right] =角(a)
top_left = a(1,1);
top_right = a(1,端);
bottom_left = a(结束,1);
bottom_right = a(结束,结束);
结尾
它给了我这个:
>> A = RANDI(100,4,5)
???用于输入“双”的输入参数的未定义功能或方法'RANDI'。
而m-file在当前目录中
1条评论
斯蒂芬Cobeldick.
斯蒂芬Cobeldick. 20月19日
@nor el houda bouhaddoun :请向我们展示此命令的输出:
哪个兰迪 - 所有人
您使用的是matlab版本的?
这是您自己的计算机和Matlab安装,或您的学校/大学/无论如何?

登录评论。


Dharmavaram Shivakrishna
Dharmavaram Shivakrishna 于2020年6月21日
有人能告诉我错误吗?
函数[top_left,top_right,bottom_left,bottom_right]= corner (A)
top_left = a(1,1)
top_right = a(1,端)
bottom_left = (, 1)
bottom_right =(结束,结束)
结尾

类别

社区寻宝

找到Matlab Central中的宝藏,并发现社区如何帮助您!

开始狩猎!