Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Z D
Z D le 18 Sep 2017
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

Réponses (1)

Walter Roberson
Walter Roberson le 18 Sep 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.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by