Store a particular set points in a new cell array.
Ältere Kommentare anzeigen
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 Kommentare
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
am 11 Jun. 2013
Antworten (3)
Matt J
am 11 Jun. 2013
[u,~,j]=unique(floor(inputVector),'stable');
z=histc(j,1:max(j));
result = mat2cell(v,z,1)
Azzi Abdelmalek
am 11 Jun. 2013
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 Kommentare
Ricky
am 11 Jun. 2013
Azzi Abdelmalek
am 11 Jun. 2013
What do you mean by like 25.8?
Ricky
am 11 Jun. 2013
Azzi Abdelmalek
am 11 Jun. 2013
Bearbeitet: Azzi Abdelmalek
am 11 Jun. 2013
why to store 24.5 and 25.5 in the same group, what is your criterion ?
Ricky
am 11 Jun. 2013
Azzi Abdelmalek
am 11 Jun. 2013
What if you make group (24 to 25), (25 to 26), and so on ?
Ricky
am 11 Jun. 2013
Azzi Abdelmalek
am 11 Jun. 2013
You can not just tell a large difference, what is for you a large difference? 0.5,10,11000?
Ricky
am 11 Jun. 2013
Azzi Abdelmalek
am 11 Jun. 2013
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
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!