[matlab]mathworks上的cody challenge题解及一些常用函数的总结(7)

Part 7. Problem 61 - Problem 70.

Problem 61. Find state names that end with the letter A

% Given a list of US states, remove all the states that end with the letter A.
% 
% Example:
% 
%  Input  s1 = 'Alabama Montana Nebraska Vermont Nevada'; 
%  Output s2 is '   Vermont '; 

function s2 = refcn(s1)
s2 = [];
s1 = regexp(s1, 'New \w*a\>|North \w*a\>|West \w*a\>|\w*a\>', 'split');
for k = 1:length(s1)
    s2 = [s2 s1{k}];
end

UPD: 用regexprep改写。

function ans = refcn(s)
	regexprep(s, '\<((New|North|West) )?\w*a\>', '');
end

Problem 62. Elapsed Time

% Given two date strings d1 and d2 of the form yyyy/mm/dd HH:MM:SS (assume hours HH is in 24 hour mode), determine how much time, in decimal hours, separates them. Assume d2 is always later than d1.
% 
% Example:
% 
%  Input d1 = '2010/12/14 12:00:00'
%  Input d2 = '2010/12/14 13:06:36'
%  Output elapsed is 1.11

function elapsed = elapsed_time(d1, d2)
elapsed = 24*(datenum(d2) - datenum(d1));
datenum可以将一个日期格式的字符串转换为距离0/0/0 0:00:00的时间,单位是小时。

Problem 63. Encode Roman Numerals

% Create a function taking a non-negative integer as its parameter and returning a string containing the Roman Numeral representation of that integer.
% 
% By convention, "modern" Roman numerals are written by expressing each digit separately starting with the leftmost digit and skipping any digit with a value of zero.
% 
% Examples
% 
%     If n is 1990 then romStr = 'MCMXC' since 1000=M, 900=CM, 90=XC.
%     If n is 2008 then romStr = 'MMVIII' since 2000=MM, 8=VIII.
%     If n is 1666 then romStr = 'MDCLXVI'.
%     If n is 0 then romStr is empty ([] and '' are both acceptable)
% 
% n will always be an integer between 0 and 3999 (inclusive).
% 
% This problem is adapted from Rosetta Code.

function romStr = dec2rom(n)
roman = {'M', 'CM', 'D', 'C
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MathWorks PCD指的是MathWorks的产品分类之一,也称为基于云的异构分布式计算平台(Parallel Computing Toolbox Cloud Provider)。 MathWorks是一家全球领先的科学和工程计算软件公司,其产品和解决方案被广泛应用于学术研究、工业设计和开发等领域。MathWorks PCD是MathWorks提供的用于并行计算的工具箱,可以帮助用户在云环境下进行高性能计算任务。 MathWorks PCD最主要的特点是为用户提供了一种灵活且高效的云计算环境,可以轻松地进行跨平台和分布式计算。用户可以将计算任务分批发送到云端进行处理,通过并行计算大幅缩短任务完成的时间。同时,MathWorks PCD还支持将不同类型的计算资源进行整合,包括本地计算机、云服务器和集群系统等,最大限度地发挥计算资源的效能。 通过使用MathWorks PCD,用户能够极大地提高计算任务的效率和性能。无论是进行大规模的数据处理、高精度的数值计算、复杂的模拟与建模还是机器学习算法的训练,MathWorks PCD都能提供相应的并行计算技术和工具。用户只需通过简单的几步操作,便可以将计算任务快速部署到云端,并且随时实时监控任务的执行情况。 总而言之,MathWorks PCD是MathWorks提供的一款强大的云计算工具箱,通过其提供的并行计算能力,可以帮助用户更高效地完成各种复杂的计算任务,提升工作效率和准确性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值