'matlab: how to add a zero zero point at the start of my graph

How can I start my graph at 0,0 without having to manually put it in? It looks like it adds an ugly kink to my graph...

Idk if I'm being silly, but I know that tanh(0) = 0, so why can't I add it into my code? I keep getting 'Array indices must be positive integers or logical values.'

sum_vec_wet = zeros(1,17);
conc_wet = 0;

sum_vec_dry = zeros(1,17);
conc_dry = 0;

for n = 1:17
    t = 1:1.72:30;

    D_dry = 3*10^-17; %diffusion coefficient
    radius_dry = (0.000000989)/2; %radius of fibre (nm)
    dry_max = 0.28;
    equation_dry= tanh(3.345*(D_dry*t(n))^0.5/radius_dry);

    conc_dry = equation_dry/dry_max;
    sum_vec_dry(n) = conc_dry*100;


    D_wet = 4*10^-16;
    radius_wet = (0.00000889)/2; %radius of fibre (nm)
    wet_max = 0.09; %mg/ml
    equation_wet = tanh(3.345*(D_wet*t(n))^0.5/radius_wet)

    conc_wet = equation_wet/wet_max;
    sum_vec_wet(n) = conc_wet*100;

end

t = [0 t]
sum_vec_wet = [0 sum_vec_wet]
sum_vec_dry = [0 sum_vec_dry]
plot(t, sum_vec_wet, 'k')
hold on
plot(t, sum_vec_dry, 'r')
hold off

ylabel('Percentage Dissolved (%)')
xlabel('Time (minutes)')
title('Geometric Model')
legend('Dry', 'Wet')

plot



Solution 1:[1]

Given the error message you have stated, you may have created a variable called tanh in your workspace. Try using which -all tanh. If there is a variable with that name (not just methods), you can use clear tanh - then try re-running your code.

PS you can also declare constants t, D_dry etc outside your loop.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 magnesium