Unexpected behavior when using end to grow arrays

when creating a video array from an image catalog, I encounter unexpected behavior. Source:

vid = [];
for i =startframe:endframe
    image = [directoryOfImages ,'\', images_names{1,i}];
    vid(:,:,:,end+1) = imread(image);
    waitbar((i-startframe) / (endframe-startframe));
end

Then I ran this code to check:

a = []; size(a)
a(end+1) = 1; size(a)

The first size was [0, 0], and the second size was [1, 1]. I got the same expected behavior in this code:

b = []; size(b)
b(:,end+1) = 1; size(b)

The first size was [0, 0], and the second size was [1, 1]. But something strange happened in this code:

c = []; size(c)
c(:,:,end+1) = 1; size(c)

whereas the first size was [0,0], and the second was [1,1,2]. It was very unexpected. I printed cand I got the following:

>>c
c(:,:,1) =

     0

c(:,:,2) =

     1

Finally, I ran this script:

c=[]; c(:,:,end)=1; size(c)

and i got it [1, 1].

- , ? c=[], [0,0,1]? size(c) ? , c(:,:,end)=1;, [1,1,1]? , c(:,:,:,end)=1?

+6
1

MATLAB, , .

MATLAB . b:

b = []; 
b(:,end+1) = 1; 

, size. . size(b,2) 1. size(b,12345)?, , 1, . 12345- b 1.

, , size(b), ! , MATLAB 2 dims N-dims, N ( ).

, , c, - , size. size(c,3) 1. , [] , MxPx0 (c(:,:,end)=img, end?), .

+5

All Articles