Allocating values in a 3D array using nested for loops
9 views (last 30 days)
Show older comments
I've created a 3D array (A) of zeros with dimensions : A=zeros(3,2,4). Using nested for loops I need to overwrite their values so the first value on the first page is 24, and all other values reduce by one each time.
Ex:
A(:,:,1)
24 23
22 21
20 19
A(:,:,2)
18 17
16 15
14 13
Other than pre-allocating A I have no idea where to start, any help would be appreciated.
0 Comments
Accepted Answer
James Tursa
on 24 Oct 2014
Since this is apparently a homework assignment, I will get you started. Since the requirement is to use nested loops, I assume the instructor wants a loop for each index. So here is the outline, one loop for each index:
A=zeros(3,2,4);
for z = __:__
for y = __:__
for x = __:__
A(x,y,z) = ____;
end
end
end
I will leave it to you to fill in the blanks.
0 Comments
More Answers (1)
See Also
Categories
Find more on Multidimensional Arrays 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!