how to craete a matrix with desired elements
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
in case of magic(n) and rand(n) an n by n matrix is created wit magic and pseudorandom elements respectively ,
how i can create a matrix of my choice(rows and col.) and with user defined elements in it .
0 commentaires
Réponse acceptée
Matt Fig
le 17 Oct 2012
Modifié(e) : Matt Fig
le 17 Oct 2012
Many ways! What do you have in mind exactly?
In the most general form:
function A = makematrix()
% Help user create an array.
% Note, error checking not written yet.
R = input('Enter the number of rows: ');
C = input('Enter the number of columns: ');
A = zeros(R,C);
for ii = 1:R
for jj = 1:C
S = sprintf('Enter element at (%i,%i): ',ii,jj);
A(ii,jj) = input(S);
end
end
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!