Use Matrix element as function input
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Fred John
 el 30 de Dic. de 2014
  
    
    
    
    
    Comentada: Fred John
 el 30 de Dic. de 2014
            Hi!
I have a 10x2 Matrix A, defined as A=R*T. Where R and T are also Matrices.
I have:
function [S] = myFunction(q,w)
S=[q 0 w 0 0;
 w 0 0 q 0;
 q w 0 0 0;
 w 0 0 q 0;
 0 0 0 w q];
q=A(1,1);
w=A(1,2);
The aim is for the function to take the (1,1) & (1,2) elements of the Matrix A and place them in the Matrix S. But I'm getting the error:
Undefined function or method 'A' for input arguments of type 'double'
Any help would be great. Thanks!
0 comentarios
Respuesta aceptada
  Geoff Hayes
      
      
 el 30 de Dic. de 2014
        Fred - I think the order of your operations is incorrect. If all of your above code (less the function signature) is in the body of the function, then the error messages makes sense since you are trying to reference the matrix A without it being passed into the function. I think that you want to do the following instead
 function [S] = myFunction(A)
 % now determine q and w
 q=A(1,1);
 w=A(1,2);
 % initialize S
 S=[q 0 w 0 0;
 w 0 0 q 0;
 q w 0 0 0;
 w 0 0 q 0;
 0 0 0 w q];
In the Command Window (or in your script), you would initialize A and then pass it as a parameter to your function, myFunction which would extract the values for q and w. Try the above and see what happens!
Más respuestas (0)
Ver también
Categorías
				Más información sobre Creating and Concatenating Matrices 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!

