필터 지우기
필터 지우기

How to select elements from a vector repecting a condition in Simulink

조회 수: 3 (최근 30일)
Josselin
Josselin 2014년 4월 9일
댓글: Niklas Nylén 2014년 4월 11일
Hi,
here is my problem:
I have in input a vector of size 31, filled alternatively with zeros or doubles (e.g. [2 8 3 0 0 0 0 0 5 7...]). What i need to do is sum the different series of non-zeros values and output them in another vector, keeping zeros between those values. With the previous vector, that would give: [13 0 12...].
I also know that there will be a problem if the number of series isn't always the same, but i think i could find a trick to avoid that problem. I did that in a Matlab function embedded in my Simulink code, but I heared Simulink code was much more performant than Matlab for embedded systems.
Do you have any idea on how I could do this?
Thank you for your answers,
Josselin

답변 (1개)

Niklas Nylén
Niklas Nylén 2014년 4월 9일
편집: Niklas Nylén 2014년 4월 9일
Although it is possible to do what you want without using simulink blocks it is a bit tricky. You could start by attempting to speeding up the simulation by using the information found in this answer: http://www.mathworks.com/matlabcentral/answers/97224
  댓글 수: 2
Josselin
Josselin 2014년 4월 9일
Hi,
thank you for your answer.
Do you know happen to know if a Matlab embedded function could cause the malfunctionnment of a program in an embedded system using simulink code?
Just to be curious, how would you proceed, roughly, to do it the tricky way using only simulink?
Niklas Nylén
Niklas Nylén 2014년 4월 11일
It is probably difficult to avoid some kind of loop. I would start by just attempting to get variable length vectors to be assigned in a simulink for loop. After that it should just be a matter of which values that should be assigned to the output vector (i.e. assign to the vector if the current value is not equal to zero or if it is equal to zero and the previous value is not equal to zero.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by