필터 지우기
필터 지우기

Combining if and for loop to iterate through a cell array

조회 수: 3 (최근 30일)
Jay Vankawala
Jay Vankawala 2020년 3월 6일
댓글: Stephen23 2020년 3월 7일
Pseudocode: I want to read column 2 of a cell array. If the value of column 2 is "x", then I want to open the matrix in column 1 of that same row (and do further code with that).
How should I construct this code? something like
for trialnumber = 1 : length(cellfilename)
if cellfilename (trialnumber, 2) == 'x'
load (cellfilename (trialnumber, 1))
end
end
That's the general idea. Already, an error is that Undefined operator '==' for input arguments of type 'cell'. Please let me know how I can accomplish this! Thank you :)

채택된 답변

Sindar
Sindar 2020년 3월 6일
편집: Sindar 2020년 3월 6일
to access the contents of a cell array, use {} instead of ():
for trialnumber = 1 : length(cellfilename)
if cellfilename{trialnumber, 2} == 'x'
load(cellfilename{trialnumber, 1})
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by