Matrix n x n input
Show older comments
I'd like to know how can I input n x n matrix where n is not a specific number?
Thanks
Answers (6)
Rok
on 21 Jul 2011
2 votes
2 Comments
Sean de Wolski
on 21 Jul 2011
So you want an determinant as an analytical function of n? No, not clear yet.
Andrei Bobrov
on 22 Jul 2011
mtx = diag(n:-1:1)
Sean de Wolski
on 21 Jul 2011
n = some_number;
matrix = rand(n)
matrix = magic(n)
matrix = zeros(n)
Please be more specific as to what you want.
Rick Rosson
on 22 Jul 2011
You do not need to know the value of n at the beginning, but depending on what you want to do with your matrix, you may or may not need to know the value of n at some point later on.
For example, in the following code, the size of the variable x does not need to be known in advance, but it does need to be known at the time you choose to call this function:
function y = timestwo(x)
y = 2*x;
end
The only thing that is known in advance is that the size of y will be the same as the size of x, whatever that is at runtime. In addition, the data class and complexity of y will also be the same as x. But again, until you call this function, there is no way to know nor is there any need to know any of these characteristics of the variables x and y.
Can you please be more specific about what you would like to do, what you have tried so far, what is not working in what you have tried, and what you would like us to help you with?
Thanks!
Rick
Rick Rosson
on 22 Jul 2011
By the way, you can always find out the value of n even if you do not know what it is in advance. You can also find out whether the matrix is square or not.
For example:
function y = dosomething(x)
[ m n ] = size(x);
if m == n
fprintf('The matrix is square \n');
else
fprintf('The matrix is NOT square \n');
end
...
end
2 Comments
Kristian Marc Lance Nery
on 9 Mar 2021
Hi sir can you help me with this project :((

Rik
on 9 Mar 2021
You already posted this as a separate question.
Neels
on 22 Jul 2011
0 votes
Are you trying to give a variable as an input, whose input is given dynamically during run time.
Rok
on 22 Jul 2011
0 votes
2 Comments
Rick Rosson
on 22 Jul 2011
The tex code does not help (at least not for me). Can you please convert the tex code to a PNG file, and then post it somewhere online where we can see it? Thanks.
Walter Roberson
on 22 Jul 2011
I do not happen to "read TeX" either..
Categories
Find more on Logical 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!