How to create a 3D variable with the third dimension is 1
15 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2023-6-27
"I want to create a 3D variable with its third dimension is 1."
A = zeros(100,100);
size(A,3)
"I would only have a 2D variable."
All arrays implicitly have infinite trailing scalar dimensions.
回答(1 个)
Nikhil Baishkiyar
2023-6-27
编辑:Nikhil Baishkiyar
2023-6-27
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!