isempty函数matlab_编程小白的MATLAB自学之路(2)

6fecb25150f271fb31c9053aba6ccce3.png

上一篇文章的最后一个问题,我在所有的解中看到了更好的答案:

function a = checkerboard(n)
f = repmat(eye(2),ceil(n/2));  %ceil函数向最大整数圆整
a = f(1:n,1:n);                
end

的确很巧妙。

11.Problem 19. Swap the first and last columns

Flip the outermost columns of matrix A, so that the first column becomes the last and the last column becomes the first. All other columns should be left intact. Return the result in matrix B.

If the input has one column, the output should be identical to the input.

Example:

 Input  A =  [ 12  4   7
                5  1   4 ];
 Output B is [  7  4  12 
                4  1   5 ];

首位列互换,先求出列数,再1与n列互换

size函数:

  • sz = size(A)
  • szdim = size(A,dim)
  • [m,n] = size(A)
  • [sz1,...,szN] = size(A)
function B = swap_ends(A)
  n=size(A,2);
  B = A;
  B(:,[1,n])=B(:,[n,1])
end

12.Problem 10. Determine whether a vector is monotonically increasing

Return true if the elements of the input vector increase monotonically (i.e. each element is larger than the previous). Return false otherwise.

Examples:

 Input  x = [-3 0 7]
 Output tf is true
 Input  x = [2 2]
 Output tf is false

判断是否是从第二项开始每一项都比前一项大的矩阵。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值