Where is the matrix operator?
Afficher commentaires plus anciens
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 commentaires
Torsten
le 5 Avr 2020
An array of zeros with one row and four columns is created using
a = zeros(1,4)
Is it that what you mean ?
Subhamoy Saha
le 5 Avr 2020
doc Matrices and Arrays
Réponse acceptée
Plus de réponses (1)
drummer
le 5 Avr 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
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!