Borrar filtros
Borrar filtros

How to create a 3D variable with the third dimension is 1

10 visualizaciones (últimos 30 días)
Zhiyun
Zhiyun el 27 de Jun. de 2023
Comentada: Stephen23 el 27 de Jun. de 2023
I want to create a 3D variable with its third dimension is 1. However, functions such as zeros, ones and rand will ignore trailing dimensions with a size of 1.
So, if I try
A = zeros(100,100,1);
I would only have a 2D variable.
  1 comentario
Stephen23
Stephen23 el 27 de Jun. de 2023
"I want to create a 3D variable with its third dimension is 1."
A = zeros(100,100);
size(A,3)
ans = 1
"I would only have a 2D variable."
All arrays implicitly have infinite trailing scalar dimensions.

Iniciar sesión para comentar.

Respuestas (1)

Nikhil Baishkiyar
Nikhil Baishkiyar el 27 de Jun. de 2023
Editada: Nikhil Baishkiyar el 27 de Jun. de 2023
This question has been asked before. This is the link
But basically Arrays in MATLAB have an implied infinitely long series of trailing singleton dimensions. You can index into them with no problem.
a = rand(100,100);
a(50,35,1)
ans = 0.7191

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by