I have a file called histShape.m with a function histShape , and some other functions also .
A general view of the code is :
%
function [outputImage] = histShape(srcimg, destimg)
PIXELS = 255 + 1;
....
....
end
%
function [outputImage] = normalizeAndAccumulate(inputImage)
PIXELS = 255 + 1;
....
....
end
%
function [pixels] = getNormalizedHistogram(histogram , inputImage)
PIXELS = 255 + 1;
....
....
end
I can use global x y z; but I’m looking for a different way .
I want to declare the variable PIXELS as global , how can I do that ?
Regards
You can gain access to a global variable inside a MATLAB function by using the keyword
global:You will usually declare the global variable in a script outside the function using the same keyword:
However, this is not strictly necessary. As long as the name of the global variable is consistent between functions, you can share the same variable by simply defining
global globalvar;in any function you write.All you should need to do is define
global PIXELS;at the beginning of each of your functions (before you assign a value to it).See the official documentation here.