MATLAB实现Excel中lookup函数查找匹配功能
时间:2022-06-11 04:41:46
在Excel中的lookup函数很容易可以实现以下功能:根据左侧序号对应的姓名匹配右侧相同序号的姓名。
现在小编就在琢磨能不能用matlab实现Excel的lookup匹配查找的功能,以下是小编写的功能函数lookup
function Result_data=Lookup(x,y,xdata) % x为需要查找的 % y为x查找的范围数据 %xdata为当x=y时候,所匹配的数据,x和xdata数据是对应的 %声明空间 index_x=zeros(1,length(x)); index_y=zeros(1,length(x)); data=num2cell(zeros(length(y),2)*NaN); for i=1:length(x) for j=1:length(y) if isequal(x(i),y(j)) index_x(i)=i; index_y(i)=j; end end end index_x(find(index_x==0))=[]; index_y(find(index_y==0))=[]; data(:,1)=y; for n=1:length(index_x)%子集长度 % data(index_y(n),2)=x(index_x(n)); data(index_y(n),2)=xdata(index_x(n)); end Result_data=data;end
读入Excel数据
clear,clc;[Num,TxT,Raw]=xlsread(‘data.xlsx’);result=Lookup(Raw(:,4),Raw(:,1),Raw(:,5))
显示处理结果:
很容易看出数据匹配。
特别说明:Lookup(x,y,xdata)中的y必须是升序或者降序排列,不能为乱序排列,否则会出现匹配错误。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
excel2016鼠标滚轮翻页键变成缩放比例大小怎么办?
![](https://img.aspxhome.com/file/2023/0/40310_0s.jpg)
Excel下拉选择项怎么设置多选 Excel下拉选择项设置多选方法
![](https://img.aspxhome.com/file/2023/7/39787_0s.png)
怎么给word文档上的图片添加边框?
![](https://img.aspxhome.com/file/2023/7/34307_0s.gif)
Word for iPad日常使用体验及吐槽分享
![](https://img.aspxhome.com/file/2023/7/34917_0s.png)
Word分栏时最后一页分为行数相等的两栏的方法
excel F4键的神奇用法,学会了效果高一倍
![](https://img.aspxhome.com/file/2023/9/a154199_0s.jpg)
word2003的页眉页脚怎么设置
excel怎么按行排序数据
![](https://img.aspxhome.com/file/2023/8/a142358_0s.png)
如何实现多人编辑同一个excel工作簿?
![](https://img.aspxhome.com/file/2023/2/a156122_0s.jpg)
excel平方根公式怎么打出来
![](https://img.aspxhome.com/file/2023/6/37396_0s.jpg)
VLOOKUP查找出现错误值,IFERROR函数来帮忙
![](https://img.aspxhome.com/file/2023/4/a142284_0s.jpg)
excel怎么设置图片透明度
Excel表格如何填充颜色
![](https://img.aspxhome.com/file/2023/5/a154105_0s.jpg)
如何在Excel中自定输入数据下拉列表?
![](https://img.aspxhome.com/file/2023/8/42698_0s.png)
Word文档标注页码如何从1开始
![](https://img.aspxhome.com/file/2023/9/18079_0s.jpg)
Win10电脑系统怎么还原成Win7系统?
![](https://img.aspxhome.com/file/2023/0/51650_0s.png)
Excel财务函数汇总
![](https://img.aspxhome.com/file/2023/8/38298_0s.png)
如何把excel表格转换成pdf格式?
![](https://img.aspxhome.com/file/2023/0/a143470_0s.png)
word不能复制粘贴怎么办,教您word不能复制粘贴的解决方法
![](https://img.aspxhome.com/file/2023/7/33517_0s.png)