How to check Spec limits
1 回表示 (過去 30 日間)
古いコメントを表示
Kanakaiah Jakkula
2018 年 4 月 28 日
編集済み: Kanakaiah Jakkula
2018 年 4 月 28 日
Hi,
I have below data:
ActualData: v1,v2,v3 are three variables
v1 v2 v3
1.2 2.3 2.9
1.5 2.9 3.4
1.6 3.3 11.3
1.3 8.0 4.9
2.1 3.7 4.2
2.0 3.1 1.3
-0.1 5.9 4.6
3.9 3.5 4.6
1.3 3.3 4.1
Spelimits
UupperLimit LowerLimit
v1 0.0 2.5
v2 2.0 3.5
v3 2.0 5.0
I want to remove entire row if any variable is out of Upper or LowerLimit my desired output:
v1 v2 v3
1.2 2.3 2.9
1.5 2.9 3.4
1.3 3.3 4.1
0 件のコメント
採用された回答
John D'Errico
2018 年 4 月 28 日
Time to learn to use MATLAB.
Lesson 1. DON'T USE THREE VARIABLES. You can't remove an entire row if all your data is in different variables. USE AN ARRAY.
Call it V. Make V have three columns. ONE array. Not three variables.
As it is, you already are thinking in terms of one row of the array of data. So why in the name of god and little green apples are you trying to split it apart?????? So combine v1,v2,v3 into one array, and leave it that way!
V = [v1,v2,v3];
Having numbered variables is a bad thing. Learn to use arrays.
Similarly, have an array of specs. So the first row might be lower specs. The second row is upper specs.
Vspecs = [0 .2 .2; 2.3 3.5 5];
Next, how do you test to see which elements of the first column (for example) are less than the spec for that column? You could do it like this:
V(:,1) < Vspecs(1,1)
That produces a boolean vector that is true whenever an element in the first column fails the desired spec.
Next, you want to combine tests together. So use the |(or) and &(and) operators. You want to find rows to remove based on something happening in that row. For example, we might do this:
(V(:,1) < Vspecs(1,1)) | (V(:,1) > Vspecs(2,1))
That handles the first column. We can just or that with a similar set of tests applied to the second column, then the third. So the final set of tests would look like this:
removebool = (V(:,1) < Vspecs(1,1)) | (V(:,1) > Vspecs(2,1)) | ...
(V(:,2) < Vspecs(1,2)) | (V(:,2) > Vspecs(2,2)) | ...
(V(:,3) < Vspecs(1,3)) | (V(:,3) > Vspecs(2,3));
So a pretty long line of MATLAB. I split it into three lines with continuations to make it readable. The result is a boolean vector that will be true whenever a row corresponds to a row that we want to remove.
We could use find now to turn that into a list of indices of rows that we wanted to remove. Better is to not bother. So learn this trick to remove all the bad rows:
V(removebool,:) = [];
That removes all rows at once that were not in the desired specs. The idea is we can use boolean indexing, a boolean (logical) vector can be used as an index into an array.
Could I have done this more simply yet? Well, yes. But you need to learn to walk before you learn to run.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Gaussian Process Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!