How to add cells (m) to an already defined array (nx1) so that the new array is (n+m x 1)

1 回表示 (過去 30 日間)
Sultan
Sultan 2015 年 12 月 2 日
編集済み: Stephen23 2015 年 12 月 31 日
I have made a search type tool which searches for only .mdl files in the folders selected so I used
a= dir(dname);
a={a(:).name}';
a(1:2)=[];
file_find = '\w*.mdl';
matchStr= regexp(a,file_find,'match');
R=matchStr(~cellfun('isempty',matchStr));
So its like a is (7 x 1) cell array after that the code does a search for only .mdl and such that R is now (3 x 1). Now this whole code is nested in a loop. When it runs second time R is (1 x 1). I want a combined cell so that the final cell array would be like 3+1=4 ( 4 x 1)
  1 件のコメント
Stephen23
Stephen23 2015 年 12 月 31 日
編集済み: Stephen23 2015 年 12 月 31 日
Why not just read the documentation and get dir to perform this task for you:
fmtch = '*.mtc';
ffull = fullfile(dname,fmtch);
A = dir(ffull);
Not only is this faster it avoids using regexp. Much neater!

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

採用された回答

Kiran
Kiran 2015 年 12 月 31 日
As the code is nested in a loop, value of R is getting overwritten each time. Instead of it, you can append the new value of R as follow:
R = { matchStr(~cellfun('isempty',matchStr)) ; R};

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by