Data size/type - Simulink
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Kaustubha Govind
2012년 3월 27일
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
K E
2012년 3월 27일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!