MATLAB Matlab - checks on imported data

  • Thread starter Thread starter bakes1
  • Start date Start date
  • Tags Tags
    Data Matlab
AI Thread Summary
The discussion revolves around using a Wii remote to collect accelerometer data, which is then exported to Excel and imported into MATLAB for analysis. The user seeks to implement a threshold check to trigger an action if any accelerometer values (x, y, z) exceed a specified threshold. The proposed approach involves using a for loop to iterate through the data sets and employing if statements to check against the threshold. Suggestions include initializing flag variables for each data column to indicate when a threshold is exceeded. The user is uncertain about the coding structure, specifically whether to incorporate this logic within the existing script or as a separate function. The example code provided illustrates the basic logic for checking values against the threshold and setting flags accordingly.
bakes1
Messages
3
Reaction score
0
A bit of background~
I'm using a wii mote to collect accelerometer data, and have the data exported to an excel document.

This data is then imported into MATLAB using :
a = xlsread(fileName); %reads in file name
x = a(:, xColNum); %time
y1 = a(:, y1ColNum); %accel value x
y2 = a(:, y2ColNum); %accel value y
y3 = a(:, y3ColNum); %accel value z

what i'd like to do next is then set a threshold check so that if any of the values within each of the sets is greater than a decided value a trigger can be set.

I'm not sure how to run the initial check on the y1, y2 ,y3 values. My first thoughts are to run a for loop on the sets and then have if statements that execute when the given values are reached. My only problem is I'm not quite sure how to code this within the m file. Also should it be part of a separate function of just below the above code.
 
Physics news on Phys.org
You could have three flag variables, one for each column, that are initialized to 0 and are set if you find a value that is above the threshold in a particular column. If you're interested only if any value in any of the three columns is above the threshold, you can probably get by with just one flag variable.

Code:
flag1 = 0
flag2 = 0
flag3 = 0
Threshold = 10000 % or whatever

for i=1:N
  if y1(i) >= Threshold
    flag1 = 1
  end
end
 

Similar threads

Replies
18
Views
6K
Replies
12
Views
3K
Replies
8
Views
2K
Replies
12
Views
4K
Replies
1
Views
1K
Replies
3
Views
3K
Back
Top