当前位置: 首页 > 工具软件 > Cody > 使用案例 >

matlab cody

姜淇
2023-12-01

Problem 1 Given the variable x as your input, multiply it by two and put the result in y.

function y = times2(x) 
  y = 2*x;
end 

Problem 2 Make the vector[1 2 3 4 5 6 7 8 9 10]

function x = oneToTen
  x = [1 2 3 4 5 6 7 8 9 10];
end
function x = oneToTen
  x = [1:10];
end

Problem 4  Make a checkerboard matrix

function a = checkerboard(n)
  a = zeros(n); %构造一个全0矩阵
  a(1:2:n,1:2:n)=1;
  a(2:2:n,2:2:n)=1;
  
end
function a = checkerboard(n)
  a = ones(n); %构造n*n全1矩阵
  a(1:2:n,2:2:n)=0;
  a(2:2:n,1:2:n)=0;
end

 类似资料:

相关阅读

相关文章

相关问答