필터 지우기
필터 지우기

how can I make the matrix empty when it has the values.

조회 수: 1 (최근 30일)
Z D
Z D 2017년 9월 18일
답변: Walter Roberson 2017년 9월 18일
this is my code.
if j~= p(t,1)
D{j}(i,[1,2,3,4])=Cl(i,[1,2,3,4]);
else
Cl(i,[1,2,3,4])% here is my problem I want C1 to be empty but I do not know how to write?!
end

답변 (1개)

Walter Roberson
Walter Roberson 2017년 9월 18일
You can delete values, and you can overwrite an entire matrix with an empty matrix, but you cannot overwrite part of a matrix with emptiness, unless the matrix is a cell array.
Cl(i,:) = [];
would delete all of row #i from C1.
c1(i,1) = [];
would delete just the element in column 1 of row #i. But as a side effect, because holes are not allowed in numeric arrays, the entire array would become a single column vector, the same as if you had done:
t = c1(:); %make it a column vector
t( sub2ind(size(c1), i, 1) ) = []; %delete the one element of the column vector
c1 = t; %that is the new c1
After that, there would be no c1(i,2) because it would be down to a single column.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by