本文介绍了如何创建一个子矩阵,从满足逻辑条件的矩阵中提取每个原始数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个* .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.


  1. 如果时间i>时间i + 1跟踪原始矩阵的位置并存储在子矩阵(rangematrix)中,这个边界值

  2. 从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:

推荐答案

您可以使用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,:);

这篇关于如何创建一个子矩阵,从满足逻辑条件的矩阵中提取每个原始数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 15:05