What does "something = cell (size(session,1),1" mean/look like?

조회 수: 1 (최근 30일)
Rosie
Rosie 2017년 2월 1일
답변: David J. Mack 2017년 2월 1일
I know the "cell" function creates an array of empty cells and I know that I didn't specify what "session" looks like. But given a matrix for session, what would the above look like? Thanks.
  댓글 수: 1
Stephen23
Stephen23 2017년 2월 1일
편집: Stephen23 2017년 2월 1일
It would give an error, because you have more opening parentheses than closing parentheses. If we fix the missing last parenthesis:
something = cell (size(session,1),1)
will give a cell array with as many rows as session has, and one column.

댓글을 달려면 로그인하십시오.

답변 (2개)

John D'Errico
John D'Errico 2017년 2월 1일
Why not think about it? Look at the inside.
What does this:
size(session,1)
do? If you have no clue, then READ THE HELP for size. Suppose you broke it into two pieces:
K = size(session,1);
something = cell(K,1);
This is essentially identical to the fragment that you show, in terms of what it will do, except that it also creates a spurious variable called K. But that is not really relevant. If you know what size does, AND you understand what the cell function does, then what does it tell you?
When you see a problem too difficult for you to understand, break it down into pieces.

David J. Mack
David J. Mack 2017년 2월 1일
Hey Marie,
the above creates a column cell with n elements, where n are the number of rows of session.
Cheers, David

카테고리

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