# A task that requires multiple outputs in a specific order.

2 Ansichten (letzte 30 Tage)
Nauman Ali Khan Khilji am 19 Mai 2021
As a basic level MATLAB user, I could not solve the following problem despite several attempts. Could someone please suggest on how to solve this:
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. Solve without using loops and if-statements.
See an example run below:
>> [a, b, c, d] = corners ([ 1 2; 3 4])
a =
1
b =
2
c =
3
d =
4
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

David Fletcher am 19 Mai 2021
function [a, b, c, d] = corners(matrix)
a=matrix(1,1);
b=matrix(1,end);
c=matrix(end,1);
d=matrix(end,end);
end
It's worth going through the Matlab Onramp course to get an idea of basic indexing - this is fundamental to understanding how to use Matlab
##### 1 KommentarKeine anzeigenKeine ausblenden
Nauman Ali Khan Khilji am 20 Mai 2021
Thanks alot! I'll check out the Matlab Onramp course as well.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Operators and Elementary Operations in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by