matlab cody学习笔记 day14

之后打算每天只刷一道题目了,毕竟题目现在越来越不容易了,除了了解matlab函数适应matlab编程外,我还想把一些复杂题目的逻辑理清楚。

(1)求两个向量的内积

今天的第一道题目比较简单,可以用dot函数,也可以直接相乘,直接相乘的时候注意矩阵转置,这两种方法的时间复杂度是一样的。

答:

function z = your_fcn_name(x,y)

z = dot(x,y);

答:

function z = your_fcn_name(x,y)

z = x*y‘;

(2)第二题也很简单,求数组长度,直接length函数就好了。

(3)Return the first and last characters of a character array

Return the first and last characters of a character array, concatenated together. If there is only one character in the character array, the function should give that character back twice since it is both the first and last character of the character array.

Example:

stringfirstandlast('boring example') = 'be'

是不熟悉的字符串的题目,但实际上也可以理解成数字,方法是相同的。

答:

function y = stringfirstandlast(x)

  y = [x(1),x(end)];

猜你喜欢

转载自blog.csdn.net/yxnooo1/article/details/114110560