当interp1
:是数字数组和y
:是字符串数组时,是否有一种方法将x,xq
函数用作interp1(x,y,xq)
?
或者你能想出一种等价的矢量方法来解决这个问题吗?
不过,我不想转换为表并使用tablelookup
。
示例:
x = [1, 3, 4, 7, 8];
y = ["A", "A", "B", "C", "C"];
xq = [2.5, 5, 6.7];
发布于 2018-09-13 18:49:26
我猜你想找个最近的邻居或者有序的归罪。在这种情况下,您可以使用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"
https://stackoverflow.com/questions/52319677
复制相似问题