How do I solve this please? Write a function called 'corners' that takes a matrix as an input argument and returns four outputs

The elements at its corners in the order: 'top_left', 'top_right', 'bottom_left', 'bottom_right'. Without loops and if-statements.
An exact copy of how my code looks in the editor is below. My problem is I don't know how to test with random values in my command window. I don't know how it should be written. I'm a total beginner here though.
function [top_left, top_right, bottom_left, bottom_right]=corners(C)
top_left = C(1,1);
top_right = C(end,1);
bottom_left= C(1, end);
bottom_right = C(end,end);
end.

 Accepted Answer

C = randi([2 10],4) % give this as input in >> command window
C = 4×4
5 2 5 5 8 8 6 7 9 8 2 3 3 5 4 6
[top_left, top_right, bottom_left, bottom_right] = corners(C) % similarly this line
top_left = 5
top_right = 3
bottom_left = 5
bottom_right = 6
function [top_left, top_right, bottom_left, bottom_right]=corners(C) % save this program in script file same name % corners%
top_left = C(1,1);
top_right = C(end,1);
bottom_left= C(1, end);
bottom_right = C(end,end);
end

1 Comment

save this program in script file same name corners and in same folder from where you call the function

Sign in to comment.

More Answers (0)

Products

Release

R2022b

Asked:

on 11 Oct 2022

Edited:

on 11 Oct 2022

Community Treasure Hunt

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

Start Hunting!