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.

 Réponse acceptée

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 commentaire

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by