The output value of the for loop is wrong

1 Ansicht (letzte 30 Tage)
rajasekar dhandapani
rajasekar dhandapani am 19 Jun. 2019
Kommentiert: Bob Thompson am 19 Jun. 2019
Hi all,
The output structure is right but somehow the logic is wrong
please find the script below
D_Calc=[];
Filter=[];
for jj=1:12
D_Calc(:,end+1)=D(:,jj); % both D_Calc and D are same
Filter=D_Calc(D_Calc(:,jj)<PlusThreesigma(jj))
MeanFilter(:,end+1)=mean(Filter);
end
output
The filter and the mean filter value takes only the 1st column.
  4 Kommentare
Bob Thompson
Bob Thompson am 19 Jun. 2019
Ok, I was able to run your code, and I am not seeing the problem you are mentioning. For me, MeanFilter is coming out as a single row of values, with corresponding means in each column.
rajasekar dhandapani
rajasekar dhandapani am 19 Jun. 2019
yes exactly that is my problem.
the mean of each col is right. But the Filter value is not right. I am wondering whether my condition in 'Filter=D_Calc(D_Calc(:,jj)<PlusThreesigma(jj))' is checking for each column. In a for loop when the iteration goes increasing 1st, 2nd 3rd col etc.
I think the second iteration is not working somehow..always it calcualtes the first col and in second iteration it also calculates the first col.
As I said i am expecting each temporary col in the filter should be different then it can give different mean for each col.
For example if you check the last column in filter that does not corresponds to the mentioned condition.
Here you can find the last col of Filter
Filter =
0.5442
0.5337
0.5337
0.5630
0.6115
0.5630
0.6211
0.5540
0.6211
0.5540
0.6339
0.5562
As per condtion it should display the values which are less than 0.1154 (this value is from plusthreesigma last col). Therefore the displayed result is not valid

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Bob Thompson
Bob Thompson am 19 Jun. 2019
I see it now. Swap the Filter line for the following.
Filter=D_Calc(D_Calc(:,jj)<PlusThreesigma(jj),jj);
Basically, your logic produces the logic for one column, but because a specific column of D_Calc was not specified it was always looking at the first column.
  2 Kommentare
rajasekar dhandapani
rajasekar dhandapani am 19 Jun. 2019
thats is great thanks a lot for your help.
Can you also help with another problem.
Filter=D_Calc(D_Calc(:,jj)>MinusThreesigma(jj),jj);
Is it possible to merge these plus and minus three sigma in one line.
so that the final result shows only data which i need and the rest is excluded.
Bob Thompson
Bob Thompson am 19 Jun. 2019
To use more than one logical condition, use & for and, and | for or.
Filter = D_Calc(D_Calc(:,jj)>MinusThreesigma(jj) & D_Calc(:,jj)<PlusThreesigma(jj),jj)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

rajasekar dhandapani
rajasekar dhandapani am 19 Jun. 2019
I found the answer if we use the following script it works as i expected
Filter=D_Calc(:,jj);
Filter(Filter>PlusThreesigma(jj))=[];
Filter(Filter<MinusThreesigma(jj))=[];
MeanFilter(jj)=mean(Filter);

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by