How can I delete data from a variable in a table?

57 vues (au cours des 30 derniers jours)
Waleed Nowayti
Waleed Nowayti le 23 Juil 2021
Commenté : Waleed Nowayti le 3 Août 2021
How can I delete data from a variable in a table: For example,
I want to delete all rows that has 'Not Collected' under SampledDate.
  4 commentaires
Waleed Nowayti
Waleed Nowayti le 26 Juil 2021
Sorry for the incomplete information. I meant to say I want to delete the whole rows. Any row contains Not Collected under 'SampledData', I need the code to delete it!
Waleed Nowayti
Waleed Nowayti le 3 Août 2021
This is what I did Rik, and it is working for me!
W = table2cell(TEST);
IndexW = find(contains(W(:,7), 'Not Collected'));
% I used (:,7) to locate the column instead of using its name!
TEST(IndexW,:)=[];

Connectez-vous pour commenter.

Réponse acceptée

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 24 Juil 2021
In fact, it is not viable to delete only rows as dpb stated.
Otherwise, if you'd like to remove all elements of specific rows, that can be done relatively easy, e.g.:
TAB(TAB.SampledDate=='Not Collected', :)=[];
  8 commentaires
Stephen23
Stephen23 le 3 Août 2021
"In general, what is the different between these two ways?"
One checks if the table data contains the required text, the other checks if the table data is the same as that text.
"Why is it giving the same output and will they be different outputs if they are used in a different code?"
Just like any functions, they will give different outputs depending on the input data:
A = 'cat in hat';
B = 'hat';
contains(A,B)
ans = logical
1
strcmp(A,B)
ans = logical
0
Only you (as your code's author) can decide which one suits your needs best.
Waleed Nowayti
Waleed Nowayti le 3 Août 2021
That is amazing! I see the difference and your example is just straight to the point. Thank you so much for explaining!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables 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