![]() |
MATLAB:插值向量
如何在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 [B]回答:[/B] 这是编辑后问题的答案,即“如何插值” 您要使用[URL="http://www.mathworks.com/help/techdoc/ref/interp1.html"]interp1[/URL] 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 [url=https://stackoverflow.com/questions/4987142]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 04:58。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.