A have a struct with four very large matrices that correspond to grayscale images. Depending on the input of my function, I want to store one of those four matrices in a var
Matlab uses a "lazy copy on write" for variables. That means that if you pass your array (or all of them) to your function, they won't be duplicated unless you write into the array(s). In other words, you may not need to do what you want to do.
For example, if you store your images in a structure imgStruct
with fields firstImage
to fourthImage
, and you pass e.g. imgStruct.fourthImage
as input to the function, the array is not duplicated, even if it is called e.g. inputImage
inside the function.
If you plan to write to the image, you can create a handle class to store your image data, which is passed by reference (thus, if you modify the image inside the function, it is also modified in your base workspace).