フィルターのクリア

Matrix n x n with n is integer

3 ビュー (過去 30 日間)
David
David 2020 年 2 月 25 日
コメント済み: Steven Lord 2020 年 2 月 25 日
this is my homework: Write a function called mat_extract that takes two inputs: a matrix N and a scalar nonnegative integer n, in that order, where each dimension of N is greater than or equal to n. The function returns the n-by-n square array at the top right corner of N.
I need help with explain the last sentence ( what is it required me to do). I was confused with it because my English was bad
  1 件のコメント
James Tursa
James Tursa 2020 年 2 月 25 日
+1 For telling us up front this is homework.

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

回答 (1 件)

James Tursa
James Tursa 2020 年 2 月 25 日
編集済み: James Tursa 2020 年 2 月 25 日
Examples,
If N is a 5x7 matrix and n is 3, then your function would return N(1:3,5:7), the 3x3 sub-matrix at the top right corner.
If N is a 123x29 matrix and n is 5, then your function would return N(1:5,25:29), the 5x5 sub-matrix at the top right corner.
Etc.
So you need to write code that is generic and will do this for any matrix N and integer n.
Hint: Look at the size( ) function to get the dimensions of N.
  2 件のコメント
David
David 2020 年 2 月 25 日
Hi, Its is extremely helpful for me. I understand your example and it really helpful. One last question is that could I set the matrix N is the random 6x6 matrix ?? I always have questions if the question is not clear.
Steven Lord
Steven Lord 2020 年 2 月 25 日
The person using your code (in this case most likely the person grading your assignment, your professor and/or their teaching assistants) will pass whatever they choose into your function as N. Your function should be general enough to handle any N and n where N has at least n rows and at least n columns.
If this weren't a homework assignment you'd probably want to include code to check that N has at least n rows and at least n columns, but you can (probably) trust your professor.

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by