how to assess each cell array using for loop?

23 ビュー (過去 30 日間)
attiqa iltaf
attiqa iltaf 2020 年 11 月 12 日
編集済み: Ameer Hamza 2020 年 11 月 12 日
i am using for loop to perfrom operation on each cell array . My cell array is 512x8.

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 12 日
編集済み: Ameer Hamza 2020 年 11 月 12 日
You can use cellfun(): https://www.mathworks.com/help/matlab/ref/cellfun.html to apply a function to each cell in a cell array. It is like an implicit for-loop which will iterate over each element.
For example, you have a function 'myFun' defined as
function y = myFun(x)
%code
end
and call cellfun() like this
C; % 512x8 cell array
C_out = cellfun(@myFun, C);
This will only work if myFun returns a scalar. If it returns a vector, then use following line
C_out = cellfun(@myFun, C, 'UniformOutput', 0);

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by