Where is the matrix operator?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Cynthia Moore
el 5 de Abr. de 2020
Comentada: Cynthia Moore
el 5 de Abr. de 2020
I am just getting started with MatLab. I read Desktop Basics and had just started Matrices and Arrays. I like to try things as I go, so when I gave an example of creating an array with the expression "a = 1x4", I typed that into MatLab. Of course, I got an error, because the matrix operator (if that is what the "x" is called) is not the letter "x". But to my frustration, it does not tell me where that operator is or how to enter it. IMHO, this is a very serious flaw. An introductory doc should never show an example that it has not already explained how to enter.
So how do I enter the matrix operator so I can experiment with "1x4"?
2 comentarios
Torsten
el 5 de Abr. de 2020
An array of zeros with one row and four columns is created using
a = zeros(1,4)
Is it that what you mean ?
Respuesta aceptada
Steven Lord
el 5 de Abr. de 2020
The command to create the array is in the box that looks like this:
a = [1 2 3 4]
The text below that box is not what you're supposed to enter into MATLAB, it shows you what will be displayed in the Command Window as the result of that command. Try entering that line of code above at the prompt, either >> or EDU>>, in the Command Window and press Enter to execute it.
The x in that result separates the sizes in the different dimensions. As created by that command the variable a is an array with 1 row and 4 columns, so 1x4.
Más respuestas (1)
drummer
el 5 de Abr. de 2020
the letter 'x' in programming represents the character 'x', i.e., the letter x.
The corresponding representation you wish: a vector of 1-by-4 is written another (completely) different way.
MATLAB has a few ways to do what you want.
a = ones(1,4) % ones is a function that returns an array or matrix with all elements equal 1.
% The first index represent the rows, and the second, the columns.
% a matrix of one row is an array.
You can also mannualy type your array:
b = [1 2 3 4]
To see the information of your variables you just create, just type
whos a
whos b
You're gonna see that you have a vector of '1 x 4' elements
Additional info:
Multiplication in programming language, i.e. the corresponding of '4 x 3' is 4 * 3.
So, even if you correctly typed
a = 1 * 4
Your ouput is rather a simple multiplication, and not a vector, AT ALL.
Cheers
0 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!