Data size/type - Simulink
Show older comments
Hello all,
I'm working on a project using Simulink. What I'm trying to do is to get the index of a vector using "find", e.g. k=find(u==max(u)), where "u" is the vector. However when I try to plug in "k" into other command line, e.g. y=u(k-1,k+1), the debugger pops up a message saying "k" is not scalar and it has dimension [?: x 1]. I haven't seen that before since using "numel" in Simulink doesn't issue that type of errors. Any hint is welcome. Thanks in advance.
Answers (1)
Kaustubha Govind
on 27 Mar 2012
0 votes
I am assuming that you are using the MATLAB Function block to run this code in Simulink? It seems like the issue is that the output of the FIND function is a vector that can be of any length, and the length depends on how many elements in 'u' are equal to max(u). Typically, variables whose size could change at run-time need to be declared as variable-size using the coder.varsize directive, with the [size(u) 1] specified as the upper-bound for the size of 'k'. Even after you have done that, you need to account for the fact that 'k' could be a vector. In which case, something like y=u(k-1,k+1) will error out even in MATLAB.
Categories
Find more on String in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!