Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Array slicing
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===1970s: [[MATLAB]] === <syntaxhighlight lang="matlabsession"> >> A = round(rand(3, 4, 5)*10) % 3x4x5 three-dimensional or cubic array >> A(:, :, 3) % 3x4 two-dimensional array along first and second dimensions ans = 8 3 5 7 8 9 1 4 4 4 2 5 >> A(:, 2:3, 3) % 3x2 two-dimensional array along first and second dimensions ans = 3 5 9 1 4 2 >> A(2:end, :, 3) % 2x4 two-dimensional array using the 'end' keyword; works with GNU Octave 3.2.4 ans = 6 1 4 6 10 1 3 1 >> A(1, :, 3) % single-dimension array along second dimension ans = 8 3 5 7 >> A(1, 2, 3) % single value ans = 3 </syntaxhighlight> The <code>:</code> operator implements the stride syntax (<code>lower_bound:upper_bound[:stride]</code>) by generating a vector. <code>1:5</code> evaluates as <code>[1, 2, 3, 4, 5]</code>. <code>1:9:2</code> evaluates as <code>[1, 3, 5, 7, 9]</code>. A bare <code>:</code> evaluates the same as <code>1:end</code>, with <code>end</code> determined by context.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)