how to craete a matrix with desired elements
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Matt Fig
on 17 Oct 2012
Edited: Matt Fig
on 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
More Answers (1)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!