Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
如何在MATLAB中内插向量?
例如,我有以下矩阵: M= 1 10 2 20 3 30 4 40 M的第一列表示x坐标的独立参数,而M的第二列表示输出或y坐标。 我也有以下输入向量: a = 2.3 2.1 3.5 对于每个值a ,我要确定输出插值后的结果会是什么。在这种情况下,给定a ,我想回报 23 21 35 回答: 这是编辑后问题的答案,即“如何插值” 您要使用interp1 M = [1 10;2 20;3 30;4 40]; a = [2.3;2.1;3.5;1.2]; interpolatedVector = interp1(M(:,1),M(:,2),a) interpolatedVector = 23 21 35 12 这是问题“在向量中找到两个最接近的条目”的答案,即编辑之前的原始问题。 x=[1,2,3,4,5]'; %'# a =3.3; %# sort the absolute difference [~,idx] = sort(abs(xa)); %# find the two closest entries twoClosestIdx = idx(1:2); %# turn it into a logical array %# if linear indices aren't good enough twoClosestIdxLogical = false(size(x)); twoClosestIdxLogical(twoClosestIdx) = true; twoClosestIdxLogical = 0 0 1 1 0 更多&回答... |
![]() |
![]() |