creating multiple variables from a vector
古いコメントを表示
i have a vector [185 186 188 189 192 247 248 249 250 251 252 253 254 255 625 626....] i want to group all of terms that are within 15 numbers apart together. for example vector1 = [185 186 188 189 192] vector2= [247 248 249 250 251 252 253 254 255] vectorn = [625 626....]
採用された回答
その他の回答 (2 件)
An alternative way of doing this:
[~, binnumber] = histc(V, min(V):15:max(V)+15);
vector = cell(1, max(binnumber)); %optional
for bin = 1:max(binnumber)
vector{bin} = V(find(binnumber == bin));
end
Andrei Bobrov
2014 年 8 月 20 日
編集済み: Andrei Bobrov
2014 年 8 月 21 日
EDIT
a = [185 186 188 189 192 247 248 249 250 251 252 253 254 255 625 626] ;
m = ceil(max(a))+1;
k = min(a):15:m;
k(end) = m;
[~,ii] = histc(a,k);
ii = cumsum([1;diff(ii(:))~=0]); % OR [~,~,ii] = unique(ii);
out = accumarray(ii(:),a(:),[],@(x){x})
カテゴリ
ヘルプ センター および File Exchange で Introduction to Installation and Licensing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!