13 views (last 30 days)
Show older comments
Ananth on 12 Jan 2013
Commented: Walter Roberson on 18 Apr 2023
I am beginner of Matlab, Please explain the following line. X = [X1 X2];
1 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
Jan on 12 Jan 2013
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/58605-x-x1-x2-please-explain#comment_122211
⋮
- Link
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/58605-x-x1-x2-please-explain#comment_122211
See AlsoCross Exchange Rate Calculator
The forum is not the right place to explain the basics. The Getting Started chapters of the documentation explain them exhaustively and therefore it is strongly recommended to read them carefully.
Sign in to comment.
Sign in to answer this question.
Answers (3)
Azzi Abdelmalek on 12 Jan 2013
Edited: Azzi Abdelmalek on 12 Jan 2013
Open in MATLAB Online
X1=12
X2=24
X = [X1 X2] % create a line vector X by horizontal concatenation;
Y=[X1;X2] %vertical concatenation
You have to read this
http://www.mathworks.com/matlabcentral/answers/8026-best-way-s-to-master-matlab
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Walter Roberson on 12 Jan 2013
That is the same as horzcat; see http://www.mathworks.com/help/matlab/ref/horzcat.html
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Hari on 17 Apr 2023
x=[x 1]
1 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
Walter Roberson on 18 Apr 2023
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/58605-x-x1-x2-please-explain#comment_2710118
@Hari
... more than you wanted to know ;-)
- In the case where x is an empty numeric or char array (not string or logical) of no more than 2 dimensions, then the value 1 would be converted to the same class as the input x and the resulting 1 would be assigned to become the new value of x. conversion to char is by applying char() which gives the corresponding UNICODE character positions -- for example char(1) is UNICODE U+0001 and not '1'
- In the case where x is an empty logical array of no more than 2 dimensions, then x would be assigned double precision 1 (the 1 would not be converted to logical)
- In the case where x is the 1 x 0 empty string array (no other size of empty), then the output would be "1" -- string() applied to the constant 1. Here the "1" is the character for the digit 1, U+0031, not by looking up as a binary code position, not U+0001 . conversion to string formats numeric into text; conversion to char() does not
- In the case where x is an empty string array that is not 1 x 0, then the operation is an error
- in the case where x is an empty numeric array that is not double precision, or is a char array, or logical, or string, and the array has more than 2 dimensions, then the operation is an error -- for example, [zeros(256,512,11,0,19,'single'), 1] is an error
- In the case where x is an empty double precision array of any dimension, then x would be assigned double precision 1 -- for example, [zeros(256,512,11,0,19), 1] is valid -- but only if x is double precision
- In the case where x is a numeric or char (not logical or string) row vector (exactly one row, any number of columns, no non-trivial hyperdimensions), then the value 1 would be converted to the same class as x and added to the end of the row and the output would be the input x with the converted 1 appended to the single row. conversion to char is by applying char() which gives the corresponding UNICODE character positions -- for example char(1) is UNICODE U+0001 and not '1'
- In the case where x is a logical vector (exactly one row, any number of columns, no non-trivial hyperdimensions), then x will be converted to a double precision row, and numeric 1 will be appened to that row, and the output will be a double precision row
- In the case where x is a string() vector (exactly one row, any number of colums, no non-trivial hyperdimensions), then the 1 will have string() applied to it, producing "1", and that "1" will be appended to the end of the row vector as a new element. ["abc" 1] will result in ["abc" "1"], not in "abc1" -- see the string + operator to merge strings. Here the "1" is the character for the digit 1, U+0031, not by looking up as a binary code position, not U+0001 . conversion to string formats numeric into text; conversion to char() does not
- In the case where x is not numeric or char or logical or strign, the results are defined by the class methods; the results are well-defined for some classes, but is an error for other classes
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABLanguage FundamentalsData TypesCharacters and Strings
Find more on Characters and Strings in Help Center and File Exchange
Tags
- x = [x1 x2]; please explain
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office