Cell array row deletion

11 vues (au cours des 30 derniers jours)
Daniela Valdez
Daniela Valdez le 19 Jan 2021
Commenté : 豆 张 le 18 Fév 2022
Hi! I have a cell array with a 10647x16 dimension. In the first column I have an identifying name for each row. I want to delete the rows that match the column names I have. I'll put a picture for better reference.
I want to delete the rows that match the 'filename' I write. I need to delete 40 rows.
  1 commentaire
豆 张
豆 张 le 18 Fév 2022
I'm so sorry to bother you. I would like to include this data of yours in my research paper, if it is possible, could you please send me the complete table. I really need it!! Thank you so so much~~
PS:My email:zlwww142536@163.com

Connectez-vous pour commenter.

Réponses (2)

Fangjun Jiang
Fangjun Jiang le 19 Jan 2021
c={'a',1,2;'b',3,4}
index=strcmp(c(:,1),'a')
c(index,:)=[]
  3 commentaires
Fangjun Jiang
Fangjun Jiang le 20 Jan 2021
What do you mean 40 files? 40 filenames maybe?? You can remove multiple rows in one shot.
c={'a',1,2;'b',3,4;'c',1,2;'d',2,3;'e',5,6}
filenames={'b';'d'}
index=ismember(c(:,1),filenames);
c(index,:)=[]
Adam Danz
Adam Danz le 20 Jan 2021
Modifié(e) : Adam Danz le 20 Jan 2021
If you want to match strings ignoring case, use strcmpi instead of strcmp.
If you're matching to more than 1 string while ignoring case, use
ismember(lower(c(:,1)), lower(filenames)) % or upper()

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 19 Jan 2021
Use ismember(). Something like...
fileNamePattern = 'MUSE20180113_171327_27000';
% Compare this character array to the list of them in column 1 of ca (the cell array)
% and find out which row contains it.
[~, row] = ismember({fileNamePattern}, ca(:, 1));
% Delete it
if ~isempty(row)
ca(row, :) = [];
end
Attach your cell array if that doesn't work.
  2 commentaires
Daniela Valdez
Daniela Valdez le 19 Jan 2021
Hi! I want to delete 40 files but I can't with this method. I get the following error: Subscript indices must either be real positive integers or logicals.
Image Analyst
Image Analyst le 20 Jan 2021
Did you miss the last sentence in my answer? I'll check back tomorrow for it.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Language Support dans Help Center et File Exchange

Produits


Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by