Finding frequency of repetition of a data point in a pattern
9 views (last 30 days)
I have data which has 48 data points. Please see attached figure which represents the plot of the data points. Now i need to know the frequency of certain points in the plot e.g. point 1 which is repeated twice, the bottom point is repeated only once and similarly some other points. I have got 48 data points in total but the point i am looking for might not repeat itself in the data, however, it might lie between two data points. I have tried to check the frequency of occurrence of such data points using the following code but am not getting the results as they should.
idx = (Final_Load(1,j)>=Linear_fit1(i,2)>=Final_Load(1,j+1))| ...
So what i did here is, took the point which i needed to check the frequency of, then i check if it lies between two consecutive data points. I believe i am making some mistake in the setting the criteria which make the process go wrong. Can anyone help me with this or preferably if there is a simpler way to do it more quickly and accurately. Just to clarify i am not bothered about the index, i just need the frequency (number of times the line passes through that value)!
dpb on 15 Jun 2017
Edited: dpb on 15 Jun 2017
(Final_Load(1,j)>=Linear_fit1(i,2)>=Final_Load(1,j+1)) | ...
There's not a compound comparison construct such as this in Matlab; what you have here are two logical expressions, one following the other from L to R. Using shorthand variables to reduce the clutter, the above reduces to the expression
(A>=B) >= C
Since the result of (A>=B) will always be either [0,1], the ultimate expression reduces to either
C<=0 or C<=1
depending on the first expression result. The same thing is true for the other expression as well, of course.
Let's see if can discern what we're wanting here...hmmm...no, I'm not sure I get the picture.
Your plot isn't attached, maybe that would help.
Are you looking for a count of the number of times each element in this vector is in some given range? If so, histogram may be your friend...
OK, that was one possibility considered, the double condition expression had me wondering....one of those places where the richness of Matlab syntax and vector operations shines--
fnCountCross=@(y,V) sum([0 diff(y>=V)]~=0);
I made up some data that approximate the plot; only nine points instead of 48 but you can do the points in the array something like
>> x=[1 8 16 22 30 38 40 42 47];
>> y=[0.32 0.23 0.35 0.44 0.42 0.53 0.52 0.54 0.47];
0.3200 0.2300 0.3500 0.4400 0.4200 0.5300 0.5200 0.5400 0.4700
2.0000 0 1.0000 3.0000 1.0000 4.0000 2.0000 2.0000 1.0000