Separating elements in Length vectors

1 visualizzazione (ultimi 30 giorni)
T
T il 25 Feb 2013
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 Commenti
Walter Roberson
Walter Roberson il 25 Feb 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 il 25 Feb 2013
trying to divide the list up by grouping spans of about 65.
For some reason it works with Azzi's.

Accedi per commentare.

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 25 Feb 2013
Modificato: Azzi Abdelmalek il 25 Feb 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 Commenti
Azzi Abdelmalek
Azzi Abdelmalek il 28 Feb 2013
Modificato: Azzi Abdelmalek il 28 Feb 2013
a={3.1364 0.3734 NaN 3.2622 3.0374 nan 2.9695}
idx=cellfun(@isnan,a)
a(idx)={0}
T
T il 11 Mar 2013
Modificato: T il 11 Mar 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?

Accedi per commentare.

Più risposte (3)

Walter Roberson
Walter Roberson il 25 Feb 2013
count = sum( abs(Length - S0) < 1e-12 );

Morteza
Morteza il 25 Feb 2013
Modificato: Azzi Abdelmalek il 25 Feb 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 il 25 Feb 2013
Modificato: Morteza il 25 Feb 2013
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....

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by