フィルターのクリア

Extract matrices of a particular size

3 ビュー (過去 30 日間)
ankit
ankit 2015 年 3 月 31 日
コメント済み: Hamza Ahmed 2021 年 3 月 19 日
Suppose there a cell containing matrices of different sizes. How can I extract all the (1x16) matrices in the same order which was present in the cell and store them in a different cell?
  1 件のコメント
LUI PAUL
LUI PAUL 2015 年 3 月 31 日
try it
result=cat([1],cellData1{:,:}); %Converting celldata to double.

サインインしてコメントする。

回答 (3 件)

James Tursa
James Tursa 2015 年 3 月 31 日
編集済み: James Tursa 2015 年 3 月 31 日
C = your cell array
DesiredSize = whatever; % e.g. [1 16]
Z = cellfun(@size,C,'UniformOutput',false); % get matrix sizes
X = cellfun(@isequal,Z,repmat({DesiredSize},size(Z))); % which ones match desired size
D = C(X); % Extract them into another cell array
  2 件のコメント
Michael Haderlein
Michael Haderlein 2015 年 3 月 31 日
In principle, yes, but it looks to me as if there's are more straight-forward way of getting X:
C={rand(3) rand(1,16) rand(1,9) rand(1,16)};
DesiredSize=[1 16];
X=cellfun(@(c) isequal(size(c),DesiredSize),C);
D=C(X);
Hamza Ahmed
Hamza Ahmed 2021 年 3 月 19 日
Hello i wanna loop through this
lets just say i have a 1*78 cell array and each cell has matrix of 2 columns but different number of rows my question is that how will I extract all the matrices which have number of rows greter then 2 from that cell array? any help in this regard will be much appreciated Thankyou

サインインしてコメントする。


Andrei Bobrov
Andrei Bobrov 2015 年 3 月 31 日
[a,b] = cellfun(@size,C);
out = C(ismember([a;b]',[1,16],'rows'));

ankit
ankit 2015 年 3 月 31 日
I tried
z=cellfun(@(x) length(x),new_cell); %displays the lengths of the matrices of the cell
pos=find(z==16);
now I can get positions of all the 1x16 matrices
  1 件のコメント
Andrei Bobrov
Andrei Bobrov 2015 年 3 月 31 日
No, e.g.:
>> C = {randi(20,4,4);randi(10,1,16);randi(20,1,16);randi(15,16,3)};
>> ii = cellfun(@length,C)
ii =
4
16
16
16
>>

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by