for loop through a cell array

조회 수: 65 (최근 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