Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

Walter Roberson
Walter Roberson il 18 Set 2017
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.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by