Is it possible to get a reference to a matrix in Matlab?

后端 未结 1 1249
南笙
南笙 2020-12-06 01:30

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

相关标签:
1条回答
  • 2020-12-06 02:18

    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).

    0 讨论(0)
提交回复
热议问题