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
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!