for loop through a cell array

62 ビュー (過去 30 日間)
C.G.
C.G. 2020 年 11 月 19 日
回答済み: KSSV 2020 年 11 月 19 日
I have a 2001x1 cell array containing the data from 2001 .csv files. Each cell in the array contains the data for 1 time step of a experiment run.
I want to write a for loop that can loop through each of the cells in the array and tell me which particles have a x-velocity of 0. Would anybody be able to give me a starting point?
%in the first cell of the cell array 'particle data', if the data in column 2 (x-velocity) is 0, display 'out'
%record the total number of 'out' particles in each cell of the array
%repeat for all 2001 cells in the cell array

回答 (1 件)

KSSV
KSSV 2020 年 11 月 19 日
If A is your cell array, you can access the cell suing A{1}, A{2}, ... A{i},..etc.
for i = 1:length(A)
A{i}
end
Also have a look on cell2mat where you can convert the cell into a matrix and access the elements. Also have a look on vertcat. You can get the indices of elements/ x velocity as zero using:
idx = a==0 ;
a(idx)

カテゴリ

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