How to make constants global

5 次查看(过去 30 天)
Hamish Brown
Hamish Brown 2022-10-20
编辑: the cyclist 2022-10-20
I have a number of functions in my code that i'm currently using, but i'm having to define constants each time inside the functions. is there a way to make the constants 'global' so that all functions can use them without having to be defined each time in each function?
E.g.
function[total_loss] = losses(VG,VD)
dt = 0.1; %Timestep
Vg = trapz(VG)*dt;
Vd = trapz(VD)*dt;
total_loss = Vg+Vd;
end
I've defined the timestep, dt. Is there a way to define it so that other functions can use it?

回答(1 个)

the cyclist
the cyclist 2022-10-20
编辑:the cyclist 2022-10-20
The first google hit for searching global matlab is this documentation page on how to define global variables.

类别

Help CenterFile Exchange 中查找有关 Google 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by