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

【无标题】cody练习分享

郭修平
2023-12-01

Problem 1971. Remove element(s) from cell array

function y = remove_from_cell_array(x,to_remove)
x(to_remove)=[];
 y = x;
end

Problem 1899. Convert a Cell Array into an Array

function y = your_fcn_name(x)
  y=[x{:}];
end

Problem 967. Split a string into chunks of specified length

function y = break_string(s,b)
  for i=1:length(b)
    y{i}=s(1:b(i));
    s=s(b(i)+1:end);
  end
end

Problem 380. Convert a numerical matrix into a cell array of strings

function output = matrix2cell(x)
a=string(x);
output=num2cell(a);
end

Problem 152. Create a cell array out of a struct

function c = struct2namedCell(S)
a=length(fieldnames(S));
c=cell(a,2);
c(:,1)=fieldnames(S);
c(:,2)=struct2cell(S);
end

Problem 41. Cell joiner

function out_str = cellstr_joiner(x,delim)
  out_str=strjoin(x(1,:)',delim);
end

 类似资料: