That depends. Terminology is important here: is your program a script or a function? Can you provide a MWE?
How do i make different matrices run through the same code?
    8 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Feliciano Döring
 el 20 de Abr. de 2018
  
    
    
    
    
    Comentada: Feliciano Döring
 el 23 de Abr. de 2018
            I have a program that runs a matrix through it. Now i want another matrix to run through it in a loop so that the first one runs, gives me the output and the other one runs and gives me the output. I use operations of this first matrix that i called 'D' (like sqrt(D(1,:)) so i don't know if the other matrixes that i run through the program have to be called 'D' also or how i would do it.
2 comentarios
  Feliciano Döring
 el 20 de Abr. de 2018
				
      Editada: Feliciano Döring
 el 20 de Abr. de 2018
  
			
		Respuesta aceptada
  David Fletcher
      
 el 20 de Abr. de 2018
        If your 2D matrices are of the same dimension they can be combined into a single 3D matrix:
D(:,:,1)=matrixA D(:,:,2)=matrixB D(:,:,3)=matrixC
Each matrix can be returned in the loop by indexing the third dimension
    D(:,:,1)
    D(:,:,2)
    D(:,:,3)If the matrices are of differing dimensions, they can be combined into a cell array
D={matrixA,matrixB,matrixC}
again each matrix can be obtained by indexing the cell array:
D{1}
D{2}
D{3}
...
          7 comentarios
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!


