Why do lines 1 and 2 create a matrix?

2 ビュー (過去 30 日間)
Crystal Judd Unson
Crystal Judd Unson 2021 年 4 月 25 日
コメント済み: Crystal Judd Unson 2021 年 4 月 25 日
Hi, I'm new to MATLAB. Why does this code create 2-dimensional arrays? I tried it on a Coursera course and it somehow works but I'm a little confused on how line 1 and 2 create a matrix. Thanks!
function [a,b,c,d]=corners(x)
[y,z]=size(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
end

採用された回答

David Fletcher
David Fletcher 2021 年 4 月 25 日
The code doesn't create a 2 dimensional array - it is supplied with a 2 dimensional array (argument x) and the function returns the values that are at the corners of that array
function [a,b,c,d]=corners(x)
[y,z]=size(x); %Gets the size of x - values not used in the function so largely serves no purpose
a=x(1,1); %top left value returned
b=x(1,end); %top right value returned
c=x(end,1); %bottom left value returned
d=x(end,end); %bottom right value returned
end
  1 件のコメント
Crystal Judd Unson
Crystal Judd Unson 2021 年 4 月 25 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by