C(:,s) = g(:); what values of g will be stored in C(:,s)?
조회 수: 1 (최근 30일)
이전 댓글 표시
C(:,s) = g(:); what values of g will be stored in C(:,s)? how it will be stored in C(:,s)? will this colon differs for every new line?
댓글 수: 0
답변 (1개)
Walter Roberson
2018년 9월 7일
C(:,s) = g(:); what values of g will be stored in C(:,s)
All values of g will be stored. If C is not initialized yet then numels(g) will define the number of rows to be created in C. If C is already initialized then if numels(g) does not match the number of rows already in C then you would get an error.
how it will be stored in C(:,s)?
g(:) reshapes the entries of g into a single column vector. The order in the column vector is the order that the entries originally occurred in memory. MATLAB stores in "column major order", so g(1,1) is followed by g(2,1) then g(3,1) and so on down column 1, and then immediately after that in memory would be the first item of column 2, g(1,2), then g(2,2), g(3,2) and so on.
will this colon differs for every new line?
I do not think I understand the question, but, No: see what I wrote above about if C is already initialized. You would have to have the same number of total entries in g in order to do the storing. This does not require that g have the same shape each time. For example,
g = [1 2 3 4]; C(:,1) = g(:);
g = [1 2; 3 4]; C(:,2) = g(:); %valid because g has the same number of total entries and those get reshaped to a column vector before trying to store
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!