2,300 views (last 30 days)

Anuj
on 21 Feb 2014

One simple way for this can be, Suppose you have square matrix of order n. So you have n^2 elements. You can enter all the elements one by one and change it into square matrix like this-

n=input('order of your square matrix is? ')

for i=1:n^2;

a(i)=input('elements-');

end

a=reshape(a,n,n)'

Regards

Akash h.r
on 16 Aug 2016

m=input('row')

n=input('column')

for i=1:m

for j=1:n

a(i,j)=input('elements-')

end

end

a=reshape(a,m,n)

Bhupendra Raj Acharya
on 6 Feb 2020

m=input('row')

n=input('column')

for i=1:m

for j=1:n

a(i,j)=input('elements-')

end

end

a=reshape(a,m,n)

Josipa Petricevic
on 5 Dec 2020

what I have to write in command window instead a(i,j)=input('elements-')?

Walter Roberson
on 5 Dec 2020

The above code is valid in the command window -- though I would recommend putting in extra spaces,

m=input('row ')

n=input('column ')

for i=1:m

for j=1:n

a(i,j)=input('elements- ')

end

end

a=reshape(a,m,n)

Amjad Alotaibi
on 19 Feb 2020

m=input('row')

n=input('column')

for i=1:m

for j=1:n

a(i,j)=input('elements-')

end

end

a=reshape(a,m,n)

tbaracu
on 18 Jan 2021

Walter Roberson
on 18 Jan 2021

Lam Nguyen Van
on 24 Mar 2020

help me. I want to input symbols matrix. ex: [a b c; f a h]

Mehedi Hasan
on 9 Sep 2020

How to take matrix from user. Calculate the mean, variance, covariance and standard

deviation for that matrix. Draw the histogram graph.

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 1 Comment

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/117017-how-do-i-create-a-square-matrix-based-on-user-input#comment_385558

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/117017-how-do-i-create-a-square-matrix-based-on-user-input#comment_385558

Sign in to comment.