Data size/type - Simulink
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Kaustubha Govind
el 27 de Mzo. de 2012
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.
2 comentarios
K E
el 27 de Mzo. de 2012
If Rodolfo expects there to usually be only 1 maximum value of u, the Matlab function code could include the following line to enforce that k will always be a scalar:
if length(k) > 1
disp('Warning, more than 1 max value in u') ;
k = k(1) ;
end
Ver también
Categorías
Más información sobre Simulink Environment Customization en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!