2015-05-02 19 views
0

請解釋函數定義的含義。一個函數需要兩個輸入:一個矩陣N和一個標量n,按照這個順序,其中N的每個維度大於或等於n。該函數返回的n乘n在N的左下角正方形陣列這個函數定義是什麼意思?涉及輸入矩陣和標量

因此,我已試過,但來自解算器

function N = bottom_left(N,n) 

    N(end-n+1:end,1:n)= n 

end 
+0

這是你自己寫的代碼嗎?你試圖做一個叫做左下角的函數? – bilaly

+0

是的,我自己寫了,函數名是bottom_left –

+0

你自己測試了這個函數嗎?生成(隨機)(5x7)矩陣並打印矩陣和n = 3的輸出。 – LutzL

回答

0

該函數得到一個錯誤有兩個輸入端和Nn

N表示矩陣的尺寸。而n表示的標量值等於或小於N的尺寸。

該函數的輸出將產生一個尺寸爲n的矩形矩陣,該矩陣由其左下角的矩陣N中的值組成。新矩陣的大小將具有尺寸n

如果Nn相等,則結果矩陣將與N相同。

diagram

+0

以下是什麼?你不明白我的解釋? – bilaly

+0

即時通訊試圖但它不工作>>功能N = bottom_left(N,n) >> N(end-n + 1:end,1:n)= n >> end –

+0

您可以發佈代碼在問題中使用功能(使用編輯按鈕)並顯示您正在嘗試的內容。這將使您更容易理解問題,其他人將能夠更輕鬆地獲益。 – bilaly

0
function bottom_left 
g = input(' Enter the number of rows : '); 
h = input(' Enter the number of columns : '); 
n = input(' Enter the dimension n of the square array you want to have : '); 

fprintf('A square matrix of the dimensions you enyered is \n') 
A = rand(n,n) 

if g < n || h < n 
    fprintf(' Please note that dimensions of the matrix must be greater than the number you entered! \n '); 
else 
    N = randi(100,g,h) 
    N(g-n+1:end,1:n) = A 

end 

希望這有助於!

相關問題