フィルターのクリア

How to EFFICIENTLY extract different length of vector from a different cell container?

1 回表示 (過去 30 日間)
Dear all, the idea was to extract different length of vector from a different cell container as demonstrated at the code below. However, I wonder if we can achieve the same procedure using CELLFUN instead. I really appreciate for any tips.
Thanks in advance
Data_CELL = {randi(9, 10,1),randi(9, 6,1),randi(9, 12,1),randi(9, 12,1)};
Extracttill=[4 4 10 9]';
ExtractedData=cell(4,1);
for f_x=1:4
data=Data_CELL{1,:};
ExtrcFUntl=Extracttill(f_x,1);
ExtractedData{f_x,1}=data(1:ExtrcFUntl,:);
end
  2 件のコメント
KSSV
KSSV 2017 年 11 月 28 日
Note that Cellfun also uses for loop inside.
balandong
balandong 2017 年 11 月 28 日
Thanks for the heads up. However, using CELLFUN make the overall code more compact, although I think it may consume the processing time.

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

採用された回答

Jos (10584)
Jos (10584) 2017 年 11 月 28 日
編集済み: Jos (10584) 2017 年 11 月 28 日
Here is a "hidden-loop / one-liner":
Data_CELL = {randi(9, 10,1),randi(9, 6,1),randi(9, 12,1),randi(9, 12,1)};
Extracttill=[4 4 10 9]';
endExtractedData = arrayfun(@(k) Data_CELL{k}(1:Extracttill(k)),1:numel(Data_CELL),'un',0)
  2 件のコメント
balandong
balandong 2017 年 11 月 28 日
Hi Jos, Thanks for the quick reply and awesome solution. Really appreciate it.
Btw, what do you mean by Do you not want to extract the values from 1 until a specific value, rather than a single value?. Your solution above does answer my original question actually.
Jos (10584)
Jos (10584) 2017 年 11 月 28 日
Oh, sorry, I read your question to quickly ... answer updated!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by