Effacer les filtres
Effacer les filtres

adding a constant to every term in a cell array

20 vues (au cours des 30 derniers jours)
shobhit mehrotra
shobhit mehrotra le 27 Jan 2015
Commenté : Image Analyst le 28 Jan 2015
I'm trying to add a constant to every term in the cell array. For example A = {[1 2 3] [4 5 6] [7 8 9]} and I want to add 5 to each term to create a cell array B= { [6 7 8] [ 9 10 11] [ 12 13 14]} Thanks!

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 27 Jan 2015
Modifié(e) : Azzi Abdelmalek le 27 Jan 2015
A = {[1 2 3] [4 5 6] [7 8 9]}
out=cellfun(@(x) x+5,A,'un',0)
  2 commentaires
shobhit mehrotra
shobhit mehrotra le 27 Jan 2015
Perfect Thanks!
Image Analyst
Image Analyst le 28 Jan 2015
But the question I have is why are you wanting to deal with the hassle of a cell array when you don't have to. You aren't mixing data types. You don't have rows or columns with different sizes. So why aren't you simply using a simple, regular numerical array??? Why make things complicated for yourself?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by