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

博主分享了在Mathworks的Cody Challenge中完成第71到80题的心得,涉及插值、替换NaN、平衡数、回文子串、去重、字符串操作、ROT13密码、DNA N-Gram分布和括号平衡等问题,文中介绍了使用MATLAB解决这些问题的关键函数和技巧。
摘要由CSDN通过智能技术生成

Part 8. Problem 71 - Problem 80.

前几天把暑假剩的两道题过了,把cody challenge做完了。最近快放国庆了,又有大段空闲时间了,白天学学算法,晚上把这个坑填了...

后面这些代码都重写了。

Problem 71. Read a column of numbers and interpolate missing data

% Given an input cell array of strings s, pick out the second column and turn it into a row vector of data. Missing data will be indicated by the number 9999. If you encounter missing data, you should perform linear interpolation to the nearest accurate data points (missing data will not occur in the first or last element).
% 
% The first row is always descriptive text. So if the input cell array s is
% 
%  s = { ...
%     'Day  Temp'
%     '  1   -5'
%     '  2   19'
%     '  3   1'
%     '  4   9999'
%     '  5   3'};
% 
% then the output variable t is the following row vector.
% 
%  t = [-5 19 1 2 3];
% 
% Here's an example of real-world data.

function ans = read_and_interp(s)
	s = str2num(char(s(2:end)));
	id = (s(:,2) ~= 9999);
	interp1(s(id,1), s(id,2), s(:,1))';
end
先找出所有有效的数据点,然后用interp1来计算出缺失点的值。


Problem 72. Interpolator

% You have a two vectors, a and b. They are monotonic and the same length. Given a value, va, where va is between a(1) and a(end) find the a(n), a(n+1) that flank it. Now interpolate the value, vb, such that it is proportionally between b(n) and b(n+1).
% 
% va can land exactly on a value of 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值