Borrar filtros
Borrar filtros

Understanding higher dimension in MATLAB

6 visualizaciones (últimos 30 días)
chaaru datta
chaaru datta el 23 de En. de 2024
Comentada: Dyuman Joshi el 24 de En. de 2024
Hello all, I am trying to understand about higher dimensions in MATLAB, but not getting it clearly.
For example: a = rand(2,2); ----(1)
I understood that above command in MATLAB will produce random variable "a" having 2 rows and 2 columns.
But I am not getting what will be the output of say b = rand(2,2,3) or b = rand(2,2,3,4) indicates.
Thus my main query is that I am not understanding properly about higher dimension in MATLAB.
Any help in this regard will be highly appreciated.
  3 comentarios
Stephen23
Stephen23 el 24 de En. de 2024
A whimsical proposal for some names of dimensions (hopefully with minimal overlap with technical terms):
  1. row (TMW & maths)
  2. column (TMW & maths)
  3. page (TMW)
  4. book
  5. shelf
  6. section
  7. library
  8. corpus
See also:
Dyuman Joshi
Dyuman Joshi el 24 de En. de 2024
Quite a nice list you have there, @Stephen23.
I was going to propose floor between section and library, but unfortunately that overlaps with floor.
And storey/level does not have the same fit to it.

Iniciar sesión para comentar.

Respuesta aceptada

John D'Errico
John D'Errico el 23 de En. de 2024
Editada: John D'Errico el 23 de En. de 2024
Visualize a vector. For example, the vector
V = 1:5
V = 1×5
1 2 3 4 5
So the numbers 1 through 5, stored in sequence in memory. Got it? rand will do something similar.
rand(1,5)
ans = 1×5
0.5599 0.1491 0.3358 0.0136 0.0369
5 numbers, stored in the vector V.
Do you see that a vector is just a set of scalars, stacked together into a one-dimensional list of numbers?
Next, what is a 2 dimensional array?
A2d = rand(2,3)
A2d = 2×3
0.9718 0.3620 0.6652 0.4545 0.6057 0.3576
2 rows, 3 columns. But it is just a set of 6 numbers here, stored with an associated shape. In this case, a rectangular shape. We can think of it as 3 column vectors, each of length 2, as as 2 row vectors, each of length 3, if you prefer.
A2d(:,1) % the first column of A2d
ans = 2×1
0.9718 0.4545
A2d(1,:) % the first row vector stored in A2d
ans = 1×3
0.9718 0.3620 0.6652
Got it?
Next, visualize a cube. A cube has three dimensions, right? We can think of that cube as squares, packed on top of each other. But each square can be thought of as 2 dimensional arrays, and we already understand 2 dimensional arrays. (Well, I hope we do.)
So if we extend the idea of a 2-dimensional array as just a set of 1-dimensional vectors, stacked next to each other, or on top of each other, then a 3 -dimensional array is no different. I'll do this one using a vector of integers first, so you can predict what numbers will be where.
A3d = reshape(1:12,[2 2 3])
A3d =
A3d(:,:,1) = 1 3 2 4 A3d(:,:,2) = 5 7 6 8 A3d(:,:,3) = 9 11 10 12
What do we see there? The first "plane" of that array is a 2x2 matrix. We saw it displayed above, but we can extract it like this:
A3d(:,:,1)
ans = 2×2
1 3 2 4
Again, think of a higher dimensinal array as just lower dimensional arrays, stacked up.
R = rand(2,3,4)
R =
R(:,:,1) = 0.0669 0.7084 0.4073 0.5308 0.4514 0.4074 R(:,:,2) = 0.7872 0.5268 0.1943 0.7919 0.1478 0.6438 R(:,:,3) = 0.9757 0.3458 0.6599 0.5446 0.9618 0.4549 R(:,:,4) = 0.9378 0.4052 0.7834 0.1438 0.1839 0.2659
So a 2x3x4 array.
Finally, we can stack three dimensional arrays, into a 4-dimensional array. We can see tham all listed below.
b = rand(2,2,2,2)
b =
b(:,:,1,1) = 0.4676 0.0003 0.3202 0.1176 b(:,:,2,1) = 0.6656 0.8099 0.9382 0.7427 b(:,:,1,2) = 0.3774 0.8263 0.2789 0.0461 b(:,:,2,2) = 0.7243 0.2364 0.0349 0.2116
Unfortunately, our minds live in a 3-dimesinal world. They are not constructed to think in higher dimensions than 3. But surely you can follow the abstract idea of stacking lower dimensional things, to create something with one more dimension?

Más respuestas (1)

Matt J
Matt J el 23 de En. de 2024
Editada: Matt J el 23 de En. de 2024
In general,
a=rand(M,N,P,Q)
means that a will return a number when you give it 4 subscripts a(i,j,k,l) for any combination of subscripts in the ranges,
1<=i<=M
1<=j<=N
1<=k<=P
1<=l<=Q
and similarly for higher dimensions.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by