Separating elements in Length vectors
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2013년 2월 25일
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) ?
채택된 답변
Azzi Abdelmalek
2013년 2월 25일
편집: Azzi Abdelmalek
2013년 2월 25일
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
Azzi Abdelmalek
2013년 2월 28일
편집: Azzi Abdelmalek
2013년 2월 28일
a={3.1364 0.3734 NaN 3.2622 3.0374 nan 2.9695}
idx=cellfun(@isnan,a)
a(idx)={0}
추가 답변 (3개)
Morteza
2013년 2월 25일
편집: Azzi Abdelmalek
2013년 2월 25일
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
댓글 수: 0
Morteza
2013년 2월 25일
편집: Morteza
2013년 2월 25일
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....
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!