MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   我正在尝试从matlab中的两个不同文件中提取具有相同x值的行,该怎么办? (https://www.labfans.com/bbs/showthread.php?t=26383)

poster 2019-12-14 20:13

我正在尝试从matlab中的两个不同文件中提取具有相同x值的行,该怎么办?
 
更清楚地说,我想要的是从file1生成file3,但使用文件2中的x值。

例:

file 1: x1=[1 2 3 4 5 6 7 8 9 10]' y1=[11 22 33 44 55 66 77 88 99 00]' file 2: x2=[3 4 5 8 9]' y2=[333 444 555 888 999]' file 3: x2=[3 4 5 8 9]' y2=[33 44 55 88 99]'

[B]回答:[/B]

使用[URL="http://www.mathworks.com/help/techdoc/ref/ismember.html"]ISMEMBER[/URL]查找x2中的x1值以及它们的位置。

x1=[1 2 3 4 5 6 7 8 9 10]' y1=[11 22 33 44 55 66 77 88 99 00]' x2=[3 4 5 8 9]' y2=[333 444 555 888 999]' x3 = x2; y3 = y1(ismember(x1,x2)) y3 = 33 44 55 88 99

[url=https://stackoverflow.com/questions/5059558]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 05:06

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.