Where is the matrix operator?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Torsten
2020-4-5
An array of zeros with one row and four columns is created using
a = zeros(1,4)
Is it that what you mean ?
采纳的回答
Steven Lord
2020-4-5
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 个)
drummer
2020-4-5
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!