Function variables are resolved in the workspace, not a .Simulink.Signal. object
Show older comments
This is part of an encryption algorithm that produces a matrix.

Variable 'img' is resolved in workspace ('base') for block 'test01/MATLAB Function4' but it is not a 'Simulink.Signal' object.
7 Comments
Walter Roberson
on 31 Jan 2023
It sounds like system3 is not computing img based only on its inputs, and is instead retrieving img somehow.
Or possibly you have declared global img and are writing to img, but Simulink is detecting that such a variable already exists but is not a datatype that it expects.
wang
on 31 Jan 2023
Walter Roberson
on 31 Jan 2023
In https://www.mathworks.com/matlabcentral/answers/1653710-global-variable-in-simulink#comment_2009495 I posted some utility routines to create real-valued simulink signals (function RSS) and simulink parameters (function RSP) and complex-valued simulink signals (function CSS) from the MATLAB level.
Paul
on 31 Jan 2023
In system3, is img declared as global? If so, why?
Can you simplify the code in system3 such that the simplified code has the same structure as the real code and generates the same error and then post copy/paste that simplified code here? Or show the code as-is if you're willing.
Walter Roberson
on 31 Jan 2023
The user indicated "The whole algorithm runs in MATLAB and global variable img has been generated" so I suspect the flow is that the MATLAB code reads an image into a global variable and invokes simulink, and then system3 tries to pull out the global variable and modify it (thought I cannot tell whether the entire modified variable is output from the block, or if instead there is just some computation that involves the image but ends up outputing some summary information.)
Paul
on 31 Jan 2023
It would be better to copy/paste the code here as text rather than an image.
Is lambd a scalar? If not, that code won't run at all because the output of mod is a matrix and X(i) is sclar.
Also, I suspect that reshape call is going to be a problem. The code generator needs to be able to figure out the size of img based on the code and/or the properties of the input and ouputs to the function, not the values of the inputs. Unless maybe img is supposed to be a variable size array.
Setting all that aside, this code in and of itself should not be causing any errors about img being global. I think there's a lot more about the workflow that causes the the problem, which hasn't been shown here.
Accepted Answer
More Answers (0)
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!