フィルターのクリア

Info

This question is locked. 編集または回答するには再度開いてください。

Write a function called corners that takes a matrix as an input argument and returns four outputs: the elements at its four corners in this order: top_left, top_right, bottom_left and bottom_right. (Note that loops and if-statements are neither neces

100 ビュー (過去 30 日間)
Debaditya Chakraborty
Debaditya Chakraborty 2019 年 5 月 23 日
Locked: Steven Lord 2024 年 6 月 5 日
This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.
Can't find a solution to this problem im a noob, please help, example
>> [a, b, c, d] = corners([1 2; 3 4])
a =
1
b =
2
c =
3
d =
4
  12 件のコメント
SATHISHKUMAR S
SATHISHKUMAR S 2020 年 8 月 18 日
Thank you very much sir. I learned.
QueenX
QueenX 2020 年 10 月 20 日
That's really nice. Thanks a lot!

回答 (4 件)

Muhammad Barkhaya
Muhammad Barkhaya 2019 年 11 月 24 日
function [a,b,c,d]=corners(x)
a=x(1,1)
b=x(1,end)
c=x(end,1)
d=x(end,end)
end
  3 件のコメント

Yihan Liu
Yihan Liu 2019 年 9 月 22 日
Well, this one could work.
function [a,b,c,d]=corners(A)
[m,n] = size(A);
a=A(1,1); % Top left
b=A(1,n); % Top right
c=A(m,1); % Bottom left
d=A(m,n); % Bottom right
end
  1 件のコメント
Guillaume
Guillaume 2019 年 9 月 22 日
Despite Sejal Syed's comment, the function that Debaditya ended up with does work and is slightly simpler (since it uses the end keyword) instead of querying the size.

ABHIJIT BISWAS
ABHIJIT BISWAS 2020 年 11 月 22 日
編集済み: Image Analyst 2021 年 9 月 16 日
function [a, b, c, d] = corners(x)
a = x(1,1); %top left
b = x(1,end); %top right
c = x(end,1); %bottom left
d = x(end,end); %bottom right
The bottom left and bottom right are the most important part.
Check the 3rd and 4th line of code properly.
Hope this helps!
  5 件のコメント
Karan
Karan 2023 年 10 月 24 日
function [top_left,top_right,bottom_left,bottom_right] = corners(rows, columns)
e = rand(rows,columns);
top_left = e(1,1);
top_right = e(1,end);
bottom_left = e(end,1);
bottom_right = e(end,end);
end
DGM
DGM 2023 年 10 月 24 日
編集済み: DGM 2023 年 10 月 24 日
That's not an answer to the question that was asked, and it's hard to imagine the question for which it would be a practical solution.
You're supposed to take a given 2D array and return its corner elements. Instead, your function takes two size arguments and returns the corner elements of a random array of that size. In effect, the input arguments to your function are meaningless. The outputs are four random numbers. The fact that they are corner elements is completely inconsequential but in the trivial case of vectors. They're just a set of random numbers.
I think it's fair to say that this question has been exhausted. It's bad enough that people paste the same code over and over as if it's a helpful revelation. It should stand to reason that there's little use for answers that don't acknowledge the task at hand.

Sisay Girma
Sisay Girma 2024 年 2 月 23 日
function [top_left, top_right, bottom_left, bottom_right] = corners(A)
top_left=A(1,1);
top_right=A(1,end);
bottom_left=A(end,1);
bottom_right=A(end,end);
end
% Code to call your function
A = randi(100,2,2)
[top_left, top_right, bottom_left, bottom_right] = corners(A)
  2 件のコメント
Rik
Rik 2024 年 2 月 23 日
What exactly does this answer add to the other answers in this thread? What does it teach? You're more than welcome to start answering questions, but why post a solution to a homework question where equivalent answers already exist?
You might be interested in giving Cody a try if you want to post your own solution for solved questions.
DGM
DGM 2024 年 2 月 23 日
Other than a change of variable name, how is this any different? If it's not demonstrating something different, then why does it exist?

This question is locked.

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by