Issues converting a Cell to a numerical array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I am trying to get the sum of all the prime unique nummbers in cell. I am having trouble converting the cell to a numerical array so that I can use the sum and prime functions on my inputs. The inputs are normally formated as ({1, 3, 7, 7, 'a'}) and matlab ether does not recognize these values as nummbers or can not convert a cell that has both nummbers and letters into a numerical array. TO be specific I am looking for a way to remove the letter from the cell and covert the rest of the cell to an array that I can use mathmatical operations on.
0 commentaires
Réponses (1)
the cyclist
le 25 Fév 2021
Modifié(e) : the cyclist
le 25 Fév 2021
Here is one way that may work for you:
C = {1, 3, 7, 7, 'a'};
N = cell2mat(C(cellfun(@isnumeric,C)))
4 commentaires
the cyclist
le 25 Fév 2021
C = {1, 3, 7, 7, 'a'};
N = cell2mat(C(cellfun(@isnumeric,C)));
primeN = N(isprime(N))
lists only the prime numbers from C. You mentioned needing unique values somehow, so you might also need the unique function.
Voir également
Catégories
En savoir plus sur Logical 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!