繁体   English   中英

如何通过 matlab function 运行来自 R 的输入?

[英]How can I run inputs from R through a matlab function?

我有一个 matlab 代码,我想通过 R 中的代码运行 3 个输入(delta_x、cutoff_1、cutoff_2)。

首先我想知道如何保存这些以便通过 matlab 代码运行它们。 delta_x 是一个 r dataframe,单列中有大约 1000 行数据。 Cutoff 1 和 2 都是整数

代码比下面显示的要长得多,所以转换成 R 需要很长时间,而且我的时间很紧,对 matlab 不是很熟悉。

本质上,我想做的是通过我提供的 matlab 代码运行我在 r 中的 3 个输入。 有谁知道我该怎么做? 我读过一些关于 matlabr package 的东西?? 但无法弄清楚。

Matlab代码如下,供参考:

    function [start_end]=plume_finder(delta_x,cutoff_1,cutoff_2)
    
    [pks,pksloc]=findpeaks(delta_x);% find the peaks
    valley=find(islocalmin(delta_x)==1);% find the valleys
    list_va=delta_x(valley);%find the values at the valley
    %There is two possibliltes, the valley presents first or the peak present
    %first. So we have to use 'shift' to make adjustment for this.
    if valley(1)>pksloc(1)
        shift=0;
    else
    shift=1;
    end
upperlim=min(length(pks),length(valley));% Find where to stop
%pksloc(:,2:end), indicating the whether this peak point could meet the
%requirements(2:whether the peak value greater than the cut-off, 3:whether
%the peak value has significant difference from valley point on its left,
%4:whether the peak value has significant difference from valley point on
%its right--> 1 stands for yes, and 0 stands for no)
for i=1:upperlim
    if pks(i)<cutoff_1
        pksloc(i,2)=0;
    else
        pksloc(i,2)=1;
    end
end
for i=2:upperlim
    if (pks(i)-list_va(i-1+shift))<=cutoff_2
        pksloc(i,3)=0;
    else
        pksloc(i,3)=1;
    end 
end
  1. 在MATLAB中,编写一个matlab脚本,可以加载ascii.csv文件,处理数据并将结果保存到新的ascii.csv文件中。

  2. R中,将变量保存到ascii.csv文件中。

  3. 在R中,通过system() 以批处理方式调用matlab脚本,等待新处理文件的生成。

  4. R,载入处理后的数据文件,等着干什么。

PS1。 csv 文件非常简单但精度不高,可以改用 HDF5 或 SQLite 格式。

PS2。 整个事情可以逆转,通过文件系统和系统调用在 matlab 中调用一些 R 脚本。 或者从 bash 或 python 或其他电话同时拨打 R 和 MATLAB。

PS3 也可以通过 local.network 套接字连接传递数据,我现在先不谈细节。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM