The problem you are facing is that your calculations are generating NaNs:
>> zt
zt =
Columns 1 through 3
NaN + NaNi 0.0118 + 0.0000i 0.0412 + 0.0000i
Columns 4 through 6
0.0877 + 0.0000i 0.1595 + 0.0000i 0.2528 + 0.0000i
Columns 7 through 9
0.3593 + 0.0000i 0.4871 + 0.0000i 0.6422 + 0.0000i
Columns 10 through 12
0.8124 + 0.0000i 0.9962 + 0.0000i 1.2089 + 0.0000i
Columns 13 through 15
1.4452 + 0.0000i 1.6887 + 0.0000i 1.9540 + 0.0000i
Columns 16 through 18
2.2552 + 0.0000i 2.5655 + 0.0000i 2.8782 + 0.0000i
Columns 19 through 21
3.2399 + 0.0000i 3.6352 + 0.0000i 3.9282 + NaNi
Columns 22 through 24
4.0240 + 0.0000i 4.0011 + 0.0000i 3.9882 + 0.0000i
Columns 25 through 27
4.0045 + 0.0000i 4.0058 + 0.0000i 3.9947 + 0.0000i
Columns 28 through 30
3.9976 + 0.0000i 4.0051 + 0.0000i 4.0003 + 0.0000i
Columns 31 through 33
3.9955 + 0.0000i 4.0012 + 0.0000i 4.0039 + 0.0000i
Columns 34 through 36
3.9975 + 0.0000i 3.9967 + 0.0000i 4.0042 + 0.0000i
Columns 37 through 39
4.0024 + 0.0000i 3.9930 + 0.0000i 4.0006 + 0.0000i
Columns 40 through 42
4.0130 + 0.0000i NaN + NaNi 3.8118 + 0.0000i
Columns 43 through 45
3.6006 + 0.0000i 3.3945 + 0.0000i 3.2021 + 0.0000i
Columns 46 through 48
3.0022 + 0.0000i 2.7976 + 0.0000i 2.5997 + 0.0000i
Columns 49 through 51
2.4017 + 0.0000i 2.1992 + 0.0000i 1.9993 + 0.0000i
Columns 52 through 54
1.8012 + 0.0000i 1.5994 + 0.0000i 1.3993 + 0.0000i
Columns 55 through 57
1.2018 + 0.0000i 0.9992 + 0.0000i 0.7977 + 0.0000i
Columns 58 through 60
0.6041 + 0.0000i 0.4004 + 0.0000i 0.1891 + 0.0000i
Column 61
NaN + NaNi
>>
and that is why your lines look broken. You can do several things:
1) check the equations so that no NaNs are generated
or
2) deal with the NaNs a-posteriori, that is you can detect the nans and remove them or get the average between the neighbours (assuming that they are isolated)
>> ztn = isnan(zt)
ans =
1×61 logical array
Columns 1 through 16
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 17 through 32
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Columns 33 through 48
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
Columns 49 through 61
0 0 0 0 0 0 0 0 0 0 0 0 1
>>
Once you know that you have nans, you can replace them, but be aware that this code ONLY works if the NaN has neighbour values that are valid:
zt2 = [0 zt 0]; % duplicate the function and add zeros to the sides
zt2n = isnan(zt2); % find the nans
zt2(zt2n) = 0.5*zt2(find(zt2n)-1)+0.5*zt2(find(zt2n)+1); % replace the nans with the average of neighbours
plot(t,zt2(2:end-1)) % display again
Problem solved.
Hope that helps.