Regarding adding new axis to the array

56 views (last 30 days)
Hello,
I have (n*1) dimensional array, now i would like to add new axis to the array and would like to get (n*1*1) multidimensional array. I tried to do it based on the previous answers :
z2 = rand(500,1) ;
[inputStructOne(jz).cause_add_dim] = cat(3,inputStructOne(jz).cause, z2);
Howver, i am getting the answer as (500*1*2), i believe that it is trying to combine two variables but instead i want (500*1*1). In python the command is np.new axis, is there anything similar to that in matlab?
Any help will be highly appreciated.
Thanks a lot in advance.

Accepted Answer

Kiran Felix Robert
Kiran Felix Robert on 5 Feb 2021
Hi Aishwarya,
In MATLAB, a 1-D vector is a Nx1 vector similarly, any MxN vector, by-itself is a MxNx1 vector.
So the ‘cat’ command adds another layer to the existing MxNX1 vector in the third dimension which makes it a MxNx2 vector.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!