How do you initialize an N*M matrix?
    593 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Harry
 el 26 de Jun. de 2013
  
    
    
    
    
    Respondida: HARSHAVARTHINI
 el 26 de Nov. de 2024
            From the MATLAB help, it says to use:
    M = matrix(N, M)
but when I apply this it says that the function 'matrix' is not recognized.
Undefined function 'matrix' for input arguments of type 'double'.
Error in experimental (line 1)
M = matrix(3,3)
3 comentarios
Respuesta aceptada
  Leah
      
 el 26 de Jun. de 2013
        
      Editada: MathWorks Support Team
    
 el 27 de Nov. de 2018
  
      To initialize an N-by-M matrix, use the “zeros” function. For example, create a 3-by-5 matrix of zeros: 
A = zeros(3,5);
 You can then later assign specific values to the elements of “A”. 
3 comentarios
  Abhishek Inamdar
 el 6 de Jul. de 2021
				Use "X = ones(n)" and add the values based on the row and column. Use for loop to work on value addition
  israt fatema
 el 25 de Ag. de 2021
				Can you please show me how to assign value to A after initialize the N x M matrix? For example i need to create a vector 5 x 5 and with values x = 20 35 49 64 23
Más respuestas (5)
  Lokesh Ravindranathan
    
 el 26 de Jun. de 2013
        
      Editada: Lokesh Ravindranathan
    
 el 26 de Jun. de 2013
  
      I am assuming you are trying to create an empty matrix of zeros of dimensions N*M. You can try the following instead
   M = zeros(3,3)
This creates a matrix of zeros of size 3*3.
2 comentarios
  per isakson
      
      
 el 26 de Jun. de 2013
				
      Editada: per isakson
      
      
 el 26 de Jun. de 2013
  
			matrix is a function in the symbolic toolbox.
  Lokesh Ravindranathan
    
 el 26 de Jun. de 2013
				Oh. Thanks Isakson. I will update my answer. My MATLAB did not have symbolic Math toolbox.
  Pau
 el 17 de Oct. de 2018
        This should make the trick
M = double.empty(N,M,0);
https://uk.mathworks.com/help/matlab/ref/empty.html
0 comentarios
  HARSHAVARTHINI
 el 26 de Nov. de 2024
        % Define the matrix A = [4 1 9; 0 1 3; 0 1 2];
% Initialize parameters n = size(A, 1); % Size of the matrix x = rand(n, 1); % Initial guess for the eigenvector tolerance = 1e-6; % Convergence criteria max_iter = 1000; % Maximum number of iterations lambda_old = 0; % Initial eigenvalue
for k = 1:max_iter % Multiply matrix A with vector x y = A * x;
    % Normalize the vector
    x = y / norm(y);    % Compute the Rayleigh quotient (dominant eigenvalue)
    lambda = x' * A * x;    % Check for convergence
    if abs(lambda - lambda_old) < tolerance
        fprintf('Converged in %d iterations.\n', k);
        break;
    end    % Update old eigenvalue
    lambda_old = lambda;
end% Display results fprintf('Dominant Eigenvalue: %.6f\n', lambda); disp('Corresponding Eigenvector:'); disp(x);
0 comentarios
Ver también
Categorías
				Más información sobre Matrices and Arrays en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!










