有没有办法使用 interp1 作为 interp1(x,y,xq) 什么时候 x,xq :是数字数组,并且 y
interp1
interp1(x,y,xq)
x,xq
y
或者你能想出一个等价的矢量方法吗?
我不想转换为表并使用 tablelookup 不过。
tablelookup
x = [1, 3, 4, 7, 8]; y = ["A", "A", "B", "C", "C"]; xq = [2.5, 5, 6.7];
我想你需要某种近邻或有序插补。在这种情况下,你可以使用 interp1 但是插入到 指数
>> x = [1 3 4 7 8]; >> y = ["hi" "hello" "bonjour" "hallo" "hola"]; >> xq = [2 5 6]; >> yq = y(interp1(x,1:length(x),xq,'nearest')) yq = 1Ã3 string array "hello" "bonjour" "hallo"