- Using the maximum and minimum values of the second column for range comparison, which eliminates the need to compare each individual value.
- Removed the 'trial = trial + 1' line because the for-loop inherently handles the incrementation.
- The 'goodFire' matrix is now being dynamically appended to, as its size is not known in advance and cannot be predetermined.
How to filter by row and print out different row if within boundary.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
OutputData = xlsread('dataOutput.csv');
TrialOrder = xlsread('TrialOrder.csv');
% Run Data %
minVal = 33;
maxVal = 41;
a = size(OutputData,2); % # columns in dataOuput
b = (a + 1)/5; % # of Runs
c = 1; % Counter
for trial = 1:b %For # Trials
h = 0;
for i = 1:31 %For all rows
Gx = OutputData(i,(trial*5)-3);
if(Gx<minVal)
h = h + 1;
end
if(Gx>maxVal)
h = h + 1;
end
end
if (h == 0)
goodFire(1,c) = trial;
c = c+1;
end
trial = trial +1;
end
I have the above code in MATLAB currently. For my project, I am trying to filter out variables outside of my 33<Gx<41 range for every trial. This data is read from an excel csv that is labeled Output Data and layed out as follows:
A B C D E F G H I
1 # Gx Gy Gz 0 # Gx Gy
2 # Gx Gy Gz 0 # Gx Gy
3 # Gx Gy Gz 0 # Gx Gy
4 #
5 #
. #
. #
32 # Gx Gy
Columns F-IO would continue displaying data with the same formatting as columns A-E. This would also expand down to 32 rows not just 1-5.
What I am trying to acomplish is for every trial, the code should ONLY read column 2 from the A-E sqeuence and check to see if the value is within my range. It would then repeat this check for all trials (1-50: repeating the A-E format) and for all rows (1-32). If the trial is within the boundary, it is deemed successful and it should print out its respective 1st column (Column with #). Note: Gx should be within the range for every value in that column. This is why I am checking it column by column for every trial.
To do this, I implimented a counter. First it will determine which trial it is on, then I will set Gx for every row in that trial. Implimenting an if statement, It will check if the value of Gx is outside of the boundary. If it IS outside, increase the counter. If at the end of the trial, the counter reads zero, it should print out the numbers in column A for that trial. Reset the counter, move on to next trial, and repeat.
Currently, it is only printing out the trial number. I have not figured out how to print out the first coulmn of every trial instead. Any suggestions?
0 commentaires
Réponses (1)
vidyesh
le 22 Fév 2024
Hi Santiago,
I understand the problem as follows: we have a set of trials, each consisting of 5 columns. The goal is to check if all the values in the second column of each trial are within a specified range. If they are, then the first column of that trial should be added to the 'goodFire' matrix.
To achieve this, we can utilize the following code:
OutputData = readtable('dataOutput.csv');
OutputData = table2array(OutputData(:,2:end));% Remove the first column since it is not part of data
% Run Data %
minVal = 33;
maxVal = 41; % # columns in dataOuput
b = size(OutputData,2)/5; % # of Runs
goodFire = [];
for i = 1:b %For # Trials
% check if values of second row of ith trial are less than maxVAl and
% greater than minVal
if max(OutputData(:,(i-1) * 5 + 2)) < maxVal && min(OutputData(:,(i-1) * 5 + 2)) > minVal
% append first row of ith trial if condtions are satisfied
goodFire = [goodFire, OutputData(:,(i-1) * 5 + 1)];
end
end
disp(goodFire)
Following changes have been made to the code:
Please note that I've used placeholder data to match the provided dimensions for testing purposes. You may need to adjust the data import section of the code to fit the specific format of your dataset.
Hope this helps.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!