Is there a quick and easy way to insert/delete values into the middle or beginning of a cell array and/or a numerical array
    21 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Robert Garneau
 el 16 de Dic. de 2018
  
    
    
    
    
    Comentada: Robert Garneau
 el 17 de Dic. de 2018
            I have a cell array and a numerical array.  I want to insert values into the beggining, middle and end of the cell array or the numerical array.  Is there an easy way to do this.
I also want to be able to delete array elements at the beginning, middle or end of the arrays.  Same question...
0 comentarios
Respuesta aceptada
  Stephen23
      
      
 el 17 de Dic. de 2018
        Just use indexing:
>> V = randperm(9)
V =
   9   5   7   3   4   6   8   2   1
>> idx = 3;
>> val = 0;
>> V = [V(1:idx),val,V(idx+1:end)]
V =
   9   5   7   0   3   4   6   8   2   1
Note that this will work for the beginning and end too (try it with idx=0).
Más respuestas (1)
  madhan ravi
      
      
 el 16 de Dic. de 2018
        
      Editada: madhan ravi
      
      
 el 16 de Dic. de 2018
  
      a=1:11;
a(1) = somevalue%first element [] square bracket removes that element
a(fix(mean(a))) %mid element
a(end) % last element
4 comentarios
  Stephen23
      
      
 el 17 de Dic. de 2018
				"is there an easier way to do it using MATLAB Functions/abilities."
Not really. Indexing is the easiest way.
Ver también
Categorías
				Más información sobre Logical en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


