Where is the matrix operator?

3 vues (au cours des 30 derniers jours)
Cynthia Moore
Cynthia Moore le 5 Avr 2020
Commenté : Cynthia Moore le 5 Avr 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 commentaires
Torsten
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
Subhamoy Saha le 5 Avr 2020
doc Matrices and Arrays

Connectez-vous pour commenter.

Réponse acceptée

Steven Lord
Steven Lord le 5 Avr 2020
I think I see the confusion. You're looking at the first example on this documentation page, right?
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.
  1 commentaire
Cynthia Moore
Cynthia Moore le 5 Avr 2020
Yes, that's the example I am looking at.
The "a = [1 2 3 4]" was clear, although I would not use sequential numbers in all of the examples. That can convey an unwanted implication. Something like a = [29 32 74 6] would be more general.
The confusion was, as you suggest, in the next line. "a = 1x4" looks like an expression and the indented "1 2 3 4" looks like a result. This may be more of a problem for me than for most. Many years ago, I used a very powerful matrix-oriented language called APL, developed at IBM. In that language, the expression "i4" (where "i" is the Greek letter iota), would generate the vector "1 2 3 4", just as in this example. When I read that MatLab is short for Matrix Laboratory (I assumed it was "Mathematical Laboratory" since it comes from MathWorks), I immediately thought of APL.
I see now that the texst inside the shaded areas are code and the rest is text. IMHO, that "a = 1x4" line is just terrible as explanatory text. Was it too difficult for whoever wrote this to have said something like, "This command defines a as a 1x4 array (or vector):
1 2 3 4
Explanatory text, especially for code, should not look like code. It should look like English. I am amazed that I am the first person to point this out. How long has that document been around?
Anyway, thanks for the clarification. Now I can proceed with the tutorial.

Connectez-vous pour commenter.

Plus de réponses (1)

drummer
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 Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by