Cell Array, Example From Manual
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Darnell Gawdin
      
 el 27 de Abr. de 2020
  
    
    
    
    
    Comentada: Darnell Gawdin
      
 el 28 de Abr. de 2020
            I'm working on an example in the fundamental manual. I'm note sure if I understand what is happening.
Create a cell array
C = {'one','two','three';1,2,3},  
    {'one'}    {'two'}    {'three'}
    {[  1]}    {[  2]}    {[    3]}
Create a subset of the cell array
upperLeft = C(1:2,1:2)
    {'one'}    {'two'}
    {[  1]}    {[  2]}
I tried to do as above in creating the subset. I was thinking the code below should copy the cell array but it gives an error. I'm not sure I'm understanding what is going on when I do this.
CopyArray = C(1:2,1:2,1:2) 
Any help will be appreciated,
Thanks
D
0 comentarios
Respuesta aceptada
  James Tursa
      
      
 el 28 de Abr. de 2020
        
      Editada: James Tursa
      
      
 el 28 de Abr. de 2020
  
      The variable C is only a 2D variable having two dimensions.  You have requested indexing into a third dimension 
with that last 1:2, hence the error.  Similar to doing this:
>> M = [1 2 3;4 5 6]
M =
     1     2     3
     4     5     6
>> M(2,3)
ans =
     6
>> M(2,3,1:2)
Index exceeds matrix dimensions. 
What was the expected result of what you tried?  Maybe we can guide you to the correct syntax to get the result you wanted.
4 comentarios
  James Tursa
      
      
 el 28 de Abr. de 2020
				
      Editada: James Tursa
      
      
 el 28 de Abr. de 2020
  
			Yes, C(1:2,1:3) is the subset of C containing rows 1-2 and columns 1-3 of C.
Más respuestas (0)
Ver también
Categorías
				Más información sobre Matrix Indexing 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!


