【问题标题】:What does this function definition mean? involving an input matrix and a scalar这个函数定义是什么意思?涉及输入矩阵和标量
【发布时间】:2015-05-02 18:07:37
【问题描述】:

请解释函数定义的含义。一个函数有两个输入:一个矩阵 N 和一个标量 n,按此顺序排列,其中 N 的每个维度都大于或等于 n。函数返回 N 左下角的 n×n 方阵。

所以我已经尝试过了,但是从求解器那里得到了一个错误

function N = bottom_left(N,n)

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

end

【问题讨论】:

  • 这段代码是你自己写的吗?你想创建一个名为左下角的函数吗?
  • 是我自己写的,函数名是bottom_left
  • 你自己测试过这个功能吗?生成(随机)(5x7)矩阵并打印矩阵和 n=3 的输出。

标签: matlab function matrix


【解决方案1】:

此函数接受两个输入 Nn

N 表示矩阵的维度。而n 表示一个标量值,它等于或小于N 的维度。

函数的输出将生成一个维度为n 的方阵,该方阵由矩阵左下角N 中的值组成。新矩阵的大小将具有维度n

如果Nn 相等,则结果矩阵将与N 相同。

【讨论】:

  • 下面是什么?你不明白我的解释吗?
  • 我正在尝试这个,但它不起作用 >>function N = bottom_left(N,n) >>N(end-n+1:end,1:n)= n >>end
  • 您能否在问题中发布该函数的代码(使用编辑按钮)并显示您正在尝试的内容。这将使问题更容易理解,其他人将能够受益更多很容易。
【解决方案2】:
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

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 2014-04-28
    • 2015-01-30
    • 2013-06-12
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多