for loop through a cell array

24 次查看(过去 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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by