for loop through a cell array

24 views (last 30 days)
C.G.
C.G. on 19 Nov 2020
Answered: KSSV on 19 Nov 2020
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

Answers (1)

KSSV
KSSV on 19 Nov 2020
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)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!