我需要在MATLAB中具有不同行数的两列中找到等效数据

发布于 2025-01-26 11:09:45 字数 493 浏览 6 评论 0原文

我正在尝试在Matlab(2016a)中编写一些代码。我有一个28x1矩阵库。我有我的计算结果发现的数据。这些是595x1矩阵的形式。我想将数据中的每个数据与库中的数据匹配,并将匹配数据输出到屏幕上。列的数量相等,但行的数量不是。我发现的数据和库中的数据并不完全相同。因此,找到的数据为59.2,但库中的数字为60。我需要能够以这种方式匹配。 ismember函数在这里不起作用。它应该更像是min(abs(lib-data))。然后,我必须对每个匹配值(minval)进行另一个操作。例如,对于每个Minval

if En < minVal - s
  value = (En - (minVal-s)) / s
end

如果您可以帮助这种情况,我将非常感谢。

I am trying to write some code in Matlab(2016a).I have a 28x1 matrix library.I have data that I found as a result of the calculations I made. These are in the form of a 595x1 matrix. I want to match each data in the data with the data in the library and output the matching data to the screen. The number of columns is equal, but the number of rows is not.The data I found and the data in the library are not exactly the same. So the data found is 59.2 but the number in the library is 60. I need to be able to match that way. The ismember function didn't work here. It should be something more like min(abs(lib-data)). Then I have to do another operation with each of the matching values (minVal) I find. For example, for each minVal,

if En < minVal - s
  value = (En - (minVal-s)) / s
end

If you could help with this situation, I would greatly appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅听莫相离 2025-02-02 11:09:45

由于您的数据与某些lib没有完全匹配,因此ismember将无法使用。在这种情况下,使用最小差异如下。

lib = rand(28,1) * 10 + 60;
data = rand(595,1) * 10 + 60;

% Find closest values
differences = abs(data' - lib);
[~, ind] = min(differences);
closest = lib(ind);
% display data and the closest from lib
table(data, closest)

样本输出:

     data     closest
    ______    _______

     61.03    61.015 
    64.515    64.394 
    63.019    62.876 
    66.161    66.314 
    63.586    63.648 
      :          :   
    63.871    63.648 
     69.31    69.343 
    64.721    64.901 
    65.245    65.243 
    60.355    60.069 

Since your data has no exact matching to some lib, then ismember will not work. Use minimum difference in this case as follows.

lib = rand(28,1) * 10 + 60;
data = rand(595,1) * 10 + 60;

% Find closest values
differences = abs(data' - lib);
[~, ind] = min(differences);
closest = lib(ind);
% display data and the closest from lib
table(data, closest)

Sample output:

     data     closest
    ______    _______

     61.03    61.015 
    64.515    64.394 
    63.019    62.876 
    66.161    66.314 
    63.586    63.648 
      :          :   
    63.871    63.648 
     69.31    69.343 
    64.721    64.901 
    65.245    65.243 
    60.355    60.069 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文