Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

How to divide a cell into two groups based on two types of strings

2 visualizaciones (últimos 30 días)
Salad Box
Salad Box el 3 de Jun. de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi,
I have a cell, say 20 by 1, which looks like below (ignore the 879). Each one in a cell is a string such as 'bad1.png'.
As you can see, some has the suffix of '.png' and some has the suffix of '.jpg'.
How can I separate them into two groups with one group only contains '.png' and the other group only contains '.jpg'?
Thanks!

Respuestas (1)

Ameer Hamza
Ameer Hamza el 3 de Jun. de 2018
Try this
index = contains(names, '.png'); % nemes is your cell array
pngFiles = names(index);
jpgFiles = names(~index);

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by