Store a particular set points in a new cell array.

Hello Everyone,
I had asked a similar question few weeks back but I think that question was not framed properly so please excuse me for asking the same question again
I have a column vector with values
32.5
25.8
25.91
25.92
16.52
16.7
Now I want to create a cell array such that my first cell contains the first value, my second cell array contains value from 25.8 to 25.92 and finally my third cell array contains the values 16.52 and 16.7 .
How can I solve this problem.

댓글 수: 2

Matt J
Matt J 2013년 6월 11일
편집: Matt J 2013년 6월 11일
Your rule for grouping data is not clear. In your example, all numbers grouped together have the same integer part, but possibly different decimal parts. Is that the grouping rule you mean? Also, will the data belonging to the same group always neighbour each other in the input vector?
Ricky
Ricky 2013년 6월 11일
Matt in one cell the data group will always be like a neighbour. So suppose I am measuring distance of a test piece from a reference point. So if the distance is 25 mm I use a tolerance window of 24.5 to 25.5 (that is -0.5 and +0.5)

댓글을 달려면 로그인하십시오.

답변 (3개)

Matt J
Matt J 2013년 6월 11일

0 개 추천

[u,~,j]=unique(floor(inputVector),'stable');
z=histc(j,1:max(j));
result = mat2cell(v,z,1)
Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 11일

0 개 추천

A=[32.5;25.8;25.91;25.92;16.52;16.7];
out{1}=A(1);
out{2)=A(2:4);
out{3}=A(5:6);

댓글 수: 9

Ricky
Ricky 2013년 6월 11일
The problem with this is I do not know how many values I will get so after the first value 32.5 the number of next values like 25.8 can be 10 or maybe 20 . So I was looking for a more generalised solution.
What do you mean by like 25.8?
Ricky
Ricky 2013년 6월 11일
these value in column are just for example. So for example after 32.8 I can get value which is 32.1 so it gets stored in same cell array. Similarly I may get 10 or 20 different values ranging in between 24.5 to 25.5 which again get stored in the same cell array. The problem is to group the data together on basis of a value.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 11일
편집: Azzi Abdelmalek 2013년 6월 11일
why to store 24.5 and 25.5 in the same group, what is your criterion ?
Ricky
Ricky 2013년 6월 11일
These are distance of the work piece from a test object and considering that there is margin of error in reading. So I give it a tolerance window of -0.5 to +0.5.
What if you make group (24 to 25), (25 to 26), and so on ?
Ricky
Ricky 2013년 6월 11일
Not possible as I do not get values in particular sequence.
y{1} = 32.5
y{2} = 25.8,25.91,25,92
y{3} = 16.52,16.7
y{4} = 33.5,33.6,33.7
y{5} = 25.7,25.6,25.8
when there is large difference value I make a new cell array.
You can not just tell a large difference, what is for you a large difference? 0.5,10,11000?
Ricky
Ricky 2013년 6월 11일
Actually I want to save the when my object is far from the sensor and when it is closer. So I check if the distance is 32.5 mm it is far. When the distances are 25.8,25.91 these small variation can be due to sensor noise or human errors while taking readings. Similarly in the third set I know the object is around 16 mm away from sensor. Then again I see that object is now far as the distance is 33.5 or 33.6 mm from sensor.

댓글을 달려면 로그인하십시오.

Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 11일

0 개 추천

A=[32.5;25.2;25.91;25.92;16.52;16.7;17;17.45];
B=fix(A+0.5);
C=unique(B,'stable')
out=cell(numel(C),1);
for k=1:numel(C)
idx=find(ismember(B,C(k)))
out{k,1}=A(idx)
end

카테고리

도움말 센터File Exchange에서 Elementary Math에 대해 자세히 알아보기

태그

질문:

2013년 6월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by