How do i build a matrix asking the user for inputs?
Mostrar comentarios más antiguos
this is script thus far. I asked the user for the number of lines and columns but when the matrix is 3 by 3 the asnwer given by the script is a matrix with 4 columns and 2 lines. HELP
num.linhas=input('Number of lines in the matrix: ');
num.colunas=input('Number of colums in the matrix: ');
for i=1:num.linhas
M(i)=input('Number: ');
end
for j=1:num.colunas
N(j)=input('Number: ');
end
A=[M;N];
A
idx=A==0;
contador=sum(idx(:));
size(A);
sz=size(A);
N=(num.linhas.*num.colunas);
percentagem=(contador./N)*100;
fprintf('\n A matriz A apresenta %f zeros',contador)
fprintf('\n A matriz tem uma dimensão de %f linhas e %f colunas',sz)
fprintf('\n A matriz A apresenta uma percentagem de %0.1f zeros',percentagem)
Respuestas (1)
David Hill
el 22 de En. de 2021
If allowed, I would build the entire matrix with one input.
yourMatrix=input('Input your matrix in the given format, for example [1,2,3;4,5,6]: ');
Categorías
Más información sobre Dynamic System Models en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!