如何创建一个子矩阵,从满足逻辑条件的矩阵中提取每个原始数据?

编程入门 行业动态 更新时间:2024-10-28 05:13:25
本文介绍了如何创建一个子矩阵,从满足逻辑条件的矩阵中提取每个原始数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个* .txt文件有多个记录,从连接到Arduino的MPU6050。

I have a single *.txt file with multiple records, from an MPU6050 connected to Arduino.

我可以识别何时创建新记录,因为列时间从随机值重新开始,而不是以前的(从不0)。

I can recognize when a new record was made because the column time restart from a random value lower then the previous (is never 0).

该文件是一个nX7,它按照时间,ax,ay,az,gx,gy,gz

The file is a nX7 which contains in order time, ax, ay, az, gx, gy, gz

我试图从单个矩阵中提取m个子记录,所以我定义了一个逻辑if。

I am trying to extract the m subrecords from the single matrix, so i defined a logical if.

  • 如果时间i>时间i + 1跟踪原始矩阵的位置并存储在子矩阵(rangematrix)中,这个边界值
  • 从rangematrix创建一组子矩阵(子矩阵的总数将为[size(rangematrix,1)-1]。
  • 我有一个土木工程师的背景,我是一个与Matlab的noob。 感谢你的时间,谢谢你的耐心。

    I have a civil engineer background and i am a noob with Matlab. Thanks for your time, thanks for you patience.

    我试图用下面的代码解决这个问题,但我认为只是垃圾。

    I tried to solve this with the code below, but I think is only rubbish.

    %Open the file filename= uigetfile ('.txt'); fileID = fopen (filename); logmpu6050 =csvread(filename); fclose (fileID); n=length(logmpu6050); %Count every time i>i+1 where i is the i,1 element of my dataset for i=1:n-1 %Save the data of the i raw every time happens i>i+1 if logmpu6050(i,1)>logmpu6050(i+1,1); rangematrix(i,:)= logmpu6050(i,:); end end % Create a new sets of matrices from boundary values

    我还在堆栈上读了很多问题,但我没有找不到解决方案:

    I also read a lot of questions on stack but i didn't find the solution:

    MATLAB:提取矢量的第n个元素

    提取大的Matlab数据集子集

    MATLAB:提取矩阵的多个部分而不使用循环

    MATLAB:定期提取元素

    从MATLAB矩阵中提取数据,无需循环

    如何通过MATLAB中的索引从大型矩阵中提取向量

    如何使用Matlab中的条件提取矩阵的一部分

    推荐答案

    您可以使用diff。

    filename= uigetfile ('.txt'); fileID = fopen (filename); logmpu6050 =csvread(filename); fclose (fileID); n=length(logmpu6050); %Count every time i>i+1 where i is the i,1 element of my dataset rangematrix = logmpu6050(diff(logmpu6050(:,1)) > 0,:);

    更多推荐

    如何创建一个子矩阵,从满足逻辑条件的矩阵中提取每个原始数据?

    本文发布于:2023-10-31 08:06:19,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1545518.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:矩阵   创建一个   逻辑   条件   原始数据

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!