Separating elements in Length vectors

Suppose I have the following data set:
Length =
1.02219692622952
8.29383522727246
17.3975329545455
26.5394026041666
37.4131448863634
48.709668181819
51.4079249999999
61.0677
67.3565390625
76.1625590909094
85.4651375000007
94.6553875000006
105.547397159091
116.990150000001
119.621383914209
129.406797916667
133.8319
141.022715625
150.280673295453
159.456462499999
170.332771874999
181.707094886364
184.246947727274
193.971341666667
204.952635795454
214.060199999998
223.163925000002
233.997125000002
245.374622960725
247.969915909091
197.672519594595
257.617404411765
260.998768555373
268.448049999999
277.622496875
286.750634374999
297.561936363639
308.926818749999
311.588342613638
321.184121875001
328.941806034484
347.096843750003
356.222274999998
367.040681250001
378.45856363637
381.169198863638
390.490676136364
337.968181250005
I want to count how many times the data runs for every
61.0677
129.406797916667
193.971341666667
257.617404411765
321.184121875001
390.490676136364
I was wondering how this can be done.

10 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 25 de Feb. de 2013
62m?
T
T el 25 de Feb. de 2013
Sorry ignore that.
Walter Roberson
Walter Roberson el 25 de Feb. de 2013
Could you expand on what you mean by "how many times the data runs" ? Are you saying that you want to use multiples of 61.0677 as the boundary to divide up the vector? If so have you considered using histc() ?
T
T el 25 de Feb. de 2013
Editada: Walter Roberson el 25 de Feb. de 2013
So what I listed was a bunch of values recorded six times. The first time being:
1.02219692622952
8.29383522727246
17.3975329545455
26.5394026041666
37.4131448863634
48.709668181819
51.4079249999999
61.0677
Second:
67.3565390625
76.1625590909094
85.4651375000007
94.6553875000006
105.547397159091
116.990150000001
119.621383914209
129.406797916667
Third:
133.8319
141.022715625
150.280673295453
159.456462499999
170.332771874999
181.707094886364
184.246947727274
193.971341666667
Fourth:
204.952635795454
214.060199999998
223.163925000002
233.997125000002
245.374622960725
247.969915909091
197.672519594595
257.617404411765
and so on.
Walter Roberson
Walter Roberson el 25 de Feb. de 2013
Those do not appear to be the same values recorded 6 times. There is no range overlap at all between the groups you give.
Azzi Abdelmalek
Azzi Abdelmalek el 25 de Feb. de 2013
What is your tolerance ?
T
T el 25 de Feb. de 2013
If we look at the separation of these points, it appears to be 60 m.
Azzi Abdelmalek
Azzi Abdelmalek el 25 de Feb. de 2013
Look at my answer.
Walter Roberson
Walter Roberson el 25 de Feb. de 2013
Are you trying to divide the list up into groups of 8 elements? Or are you trying to divide the list up by grouping spans of about 65? (Not 60 or else 61.067 would have to be in the second group; has to be at least 65 for 129.406797916667 to stay in the second group instead of moving to the third) ?
T
T el 25 de Feb. de 2013
trying to divide the list up by grouping spans of about 65.
For some reason it works with Azzi's.

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 25 de Feb. de 2013
Editada: Azzi Abdelmalek el 25 de Feb. de 2013
v=min(x):60:max(x); % x is your array
id=0;
clear out
for k=2:numel(v)
[~,idx]=min(abs(x-v(k)));
id(k)=idx;
out{k-1}=x(id(k-1)+1:id(k))
end

15 comentarios

T
T el 25 de Feb. de 2013
how would I be able to confirm the elements inside say out(1) ?
out{1}
out{2}
out{3}
out{4}
out{5}
T
T el 25 de Feb. de 2013
It works but suppose that x was a struct. How can I avoid the error:
x = [YourStructure.NameOfTheField];
T
T el 26 de Feb. de 2013
Suppose I have another function that allows the user to pick to load out{3}, how could I prompt an error if he chooses out{7}?
Walter Roberson
Walter Roberson el 26 de Feb. de 2013
Don't allow him to choose that :)
If choosing by number, then check that the number is an integer from 1 to numel(out)
T
T el 27 de Feb. de 2013
Editada: Azzi Abdelmalek el 27 de Feb. de 2013
[~,idx]=min(abs(x-v(k)));
What's the purpose of this command? Why take the minimum of the difference?
Azzi Abdelmalek
Azzi Abdelmalek el 27 de Feb. de 2013
Imagine you have successive values 53 and 100, what will you choose?
T
T el 28 de Feb. de 2013
Editada: T el 28 de Feb. de 2013
Sorry what does [~,idx] do?
Undefined function or variable '%U2a8'.
check this
x=[20 10 5 12]
[val,idx]=min(x) % check val and idx
[~,idx]=min(x), % will return only idx
T
T el 28 de Feb. de 2013
Suppose I have a vector:
3.1364 0.3734 NaN 3.2622 3.0374 2.6531 2.9695
Is there a intrinsic function that can set NaN to zero in MATLAB?
x(isnan(x))=0
T
T el 28 de Feb. de 2013
Interesting but it gives me the error:
Undefined function 'isnan' for input arguments of type 'cell'.
How could I use, findzero = find(isnan(x) == 1 ) ?
Azzi Abdelmalek
Azzi Abdelmalek el 28 de Feb. de 2013
Editada: Azzi Abdelmalek el 28 de Feb. de 2013
a={3.1364 0.3734 NaN 3.2622 3.0374 nan 2.9695}
idx=cellfun(@isnan,a)
a(idx)={0}
T
T el 11 de Mzo. de 2013
Editada: T el 11 de Mzo. de 2013
The answer you provided in your original post worked for 3 of the 4 data sets. However it fails for the following:
Length =
10.67954286
16.95905
23.80346761
30.64783654
36.26469464
45.68961071
4.470840152
40.77218235
43.1111375
60.68135227
66.89735455
73.16068807
79.94356648
86.77656042
92.33539183
96.81867216
99.15924167
101.5261402
115.3083575
121.48875
127.769138
134.6187223
141.4633148
147.0741786
151.5829937
153.9290107
156.2800205
168.5841936
174.76505
181.0298386
187.8265812
194.666433
200.1939
204.6659375
207.0010337
209.3573269
What happens is that it splits into three columns, when there should be four, with the first one being:
10.67954286
16.95905
23.80346761
30.64783654
36.26469464
45.68961071
4.470840152
40.77218235
43.1111375
60.68135227
66.89735455
73.16068807
Is there any way around this?

Iniciar sesión para comentar.

Más respuestas (3)

Morteza
Morteza el 25 de Feb. de 2013
Editada: Azzi Abdelmalek el 25 de Feb. de 2013
clc,clear
format long
Length = [
1.02219692622952
8.29383522727246
17.3975329545455
26.5394026041666
37.4131448863634
48.709668181819
51.4079249999999
61.0677
67.3565390625
76.1625590909094
85.4651375000007
94.6553875000006
105.547397159091
116.990150000001
119.621383914209
129.406797916667
133.8319
141.022715625
150.280673295453
159.456462499999
170.332771874999
181.707094886364
184.246947727274
193.971341666667
204.952635795454
214.060199999998
223.163925000002
233.997125000002
245.374622960725
247.969915909091
197.672519594595
257.617404411765
260.998768555373
268.448049999999
277.622496875
286.750634374999
297.561936363639
308.926818749999
311.588342613638
321.184121875001
328.941806034484
347.096843750003
356.222274999998
367.040681250001
378.45856363637
381.169198863638
390.490676136364
337.968181250005];
for i = 1:length(Length)
STR{i,1} = sprintf('%4.12f',Length(i));
end
S0 = input('Enter number : ');
S1 = sprintf('%4.12f',S0);
count = 0;
for i = 1:length(Length)
if strcmp(S1,STR{i,1}) == 1
count = count+1;
end
end
count
Morteza
Morteza el 25 de Feb. de 2013
Editada: Morteza el 25 de Feb. de 2013

0 votos

what is your MATLAB version?
I write this in MATLAB 2012b and it is work to find out each value, how many times repeated.
you have diffrent floating point data, without converting them into the string you will not be able to find the exact value.
Moreover your data does not have any specific character in each bunch, therefore finding the number of bunches become impossible, except by increasing rate or number of counter for each bunch may be it is possible...
As I see for each 60 period you have one bunch, may be you can use of this parameter....

Categorías

Etiquetas

Preguntada:

T
T
el 25 de Feb. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by