what does this mean , how and for what is it used ?

while playing around in the command window with arrays and matrices i tried to
print x=ones and it gave me an array of size 1*1 containing 1
x=ones(2,3) a matrix of size 2*3 containing ones ,
x=ones(2,3,4) builds the matrix of the size i wrote and repeats it 4 times
to here there are no problems i think,
x=ones(2,3,4,5,8)
this i am not sure what it excatly does and what for ,though its written in the documentations brifely that it should be an array of 2*3*4*5*8

7 commentaires

Hi Dareen,
In MATLAB, the function "ones" is used to create arrays filled with the value 1. The syntax ones(d1, d2, d3, ..., dn) creates an n-dimensional array where d1, d2, d3, ..., dn specify the size of each dimension.
For your specific case:
x = ones(2,3,4,5,8) creates a 5-dimensional array where:
  • The first dimension has a size of 2.
  • The second dimension has a size of 3.
  • The third dimension has a size of 4.
  • The fourth dimension has a size of 5.
  • The fifth dimension has a size of 8.
This results in an array with a total of elements, all of which are 1. Such high-dimensional arrays are useful in various advanced applications like data science, machine learning, signal processing, and scientific computing, where they can represent complex data sets or simulations with multiple variables or dimensions.
Manipulating and understanding these high-dimensional arrays require familiarity with MATLAB's array indexing and manipulation capabilities, enabling you to extract, analyze, and visualize the data contained within these structures effectively. Refer the documentation for further understanding:
Hope this helps.
dareen
dareen le 21 Mar 2024
Modifié(e) : dareen le 21 Mar 2024
i checked the link before posting the question to be honest ,but certainly this shed light on the for what aspect and gave a better understanding of what is meant by dimension thank u , i think i know what to search for now going to see some videos on high-dimensional arrays
Stephen23
Stephen23 le 21 Mar 2024
Modifié(e) : Stephen23 le 21 Mar 2024
"this i am not sure what it excatly does..."
The documentation already tells you exactly what it does: it creates an array with size 2x3x4x5x8.
".. and what for..."
It is for creating an array with size 2x3x4x5x8. Or any other size:
dareen
dareen le 21 Mar 2024
Modifié(e) : dareen le 21 Mar 2024
thanks alot excactly what i needed , i probably should have phrased the question better , it is more like i can see that what it does exactly is written in the documentation , but i dont really understand whats written @Stephen23
Sam Chak
Sam Chak le 21 Mar 2024
It is worth noting that visualizing an array with a size of 2x3x4x5x8 is not readily achievable in a tangible manner. Consequently, the OP raised a question regarding the functionality of the provided syntax.
Stephen23
Stephen23 le 21 Mar 2024
Modifié(e) : Stephen23 le 21 Mar 2024
Example: the motion of a rigid body in 3D space fundamentally has six degrees of freedom. Each dimension is nominally independent of the other dimensions. So if you do some measurements for along each of those six dimensions, then you could store the measured data in a 6D array.
This is fundamentally no different to 2D data (e.g. an image) or any other number of dimensions of a system.
dareen
dareen le 21 Mar 2024
Modifié(e) : dareen le 21 Mar 2024
@Stephen23 thanks the example is really useful cleared this a lot, hopefully will impelement this in future codes

Connectez-vous pour commenter.

 Réponse acceptée

The following will produce a 5-dimensional array of 2x3x5x5x8. You can access the element by specifying 5-d index
x=ones(2,3,4,5,8)
x =
x(:,:,1,1,1) = 1 1 1 1 1 1 x(:,:,2,1,1) = 1 1 1 1 1 1 x(:,:,3,1,1) = 1 1 1 1 1 1 x(:,:,4,1,1) = 1 1 1 1 1 1 x(:,:,1,2,1) = 1 1 1 1 1 1 x(:,:,2,2,1) = 1 1 1 1 1 1 x(:,:,3,2,1) = 1 1 1 1 1 1 x(:,:,4,2,1) = 1 1 1 1 1 1 x(:,:,1,3,1) = 1 1 1 1 1 1 x(:,:,2,3,1) = 1 1 1 1 1 1 x(:,:,3,3,1) = 1 1 1 1 1 1 x(:,:,4,3,1) = 1 1 1 1 1 1 x(:,:,1,4,1) = 1 1 1 1 1 1 x(:,:,2,4,1) = 1 1 1 1 1 1 x(:,:,3,4,1) = 1 1 1 1 1 1 x(:,:,4,4,1) = 1 1 1 1 1 1 x(:,:,1,5,1) = 1 1 1 1 1 1 x(:,:,2,5,1) = 1 1 1 1 1 1 x(:,:,3,5,1) = 1 1 1 1 1 1 x(:,:,4,5,1) = 1 1 1 1 1 1 x(:,:,1,1,2) = 1 1 1 1 1 1 x(:,:,2,1,2) = 1 1 1 1 1 1 x(:,:,3,1,2) = 1 1 1 1 1 1 x(:,:,4,1,2) = 1 1 1 1 1 1 x(:,:,1,2,2) = 1 1 1 1 1 1 x(:,:,2,2,2) = 1 1 1 1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 x(:,:,1,2,8) = 1 1 1 1 1 1 x(:,:,2,2,8) = 1 1 1 1 1 1 x(:,:,3,2,8) = 1 1 1 1 1 1 x(:,:,4,2,8) = 1 1 1 1 1 1 x(:,:,1,3,8) = 1 1 1 1 1 1 x(:,:,2,3,8) = 1 1 1 1 1 1 x(:,:,3,3,8) = 1 1 1 1 1 1 x(:,:,4,3,8) = 1 1 1 1 1 1 x(:,:,1,4,8) = 1 1 1 1 1 1 x(:,:,2,4,8) = 1 1 1 1 1 1 x(:,:,3,4,8) = 1 1 1 1 1 1 x(:,:,4,4,8) = 1 1 1 1 1 1 x(:,:,1,5,8) = 1 1 1 1 1 1 x(:,:,2,5,8) = 1 1 1 1 1 1 x(:,:,3,5,8) = 1 1 1 1 1 1 x(:,:,4,5,8) = 1 1 1 1 1 1
y = x(2, 1, 3, 3, 4) % one element of the 5-d array
y = 1

3 commentaires

dareen
dareen le 21 Mar 2024
i think my confusion is more related to not being familar with anything higher tha 2d arrays i understand that i am accessing data but the output format is not giving me a clear picture of where an element is and what to imagine , i think i will first begin by checking the link given by @Sudarsanan A K
"i think my confusion is more related to not being familar with anything higher tha 2d arrays"
Mathematics is not limited to working in two dimensions, why would MATLAB be?
dareen
dareen le 21 Mar 2024
makes sense this language is much more useful than i imagined

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by