简体   繁体   中英

How do I fix the following error in if-else statement in MATLAB

So I have the following code:

if tau_a == tau_b
    ana_nb = NB * exp(-t/tau_a) + t * (NA/tau_a) * exp(-(t/tau_a))
else
    ana_nb = NB * exp(-t/tau_b) + NA/((tau_a/tau_b)-1) * (exp(-t/tau_a) - exp(-t/tau_b))
end

Here NA = 100, NB = 80, tau_a = 2, tau_b = 4, t is an array of numbers (with a size of 21)

The error message I get is: "Error using *. Inner matrix dimensions must agree."

How do I fix this?

您将不得不使用元素明智的乘法.*

ana_nb = NB .* exp(-t/tau_a) + t .* (NA/tau_a) .* exp(-(t/tau_a))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM