How to change a single value on a different vector cell each time? (simulink)

조회 수: 8 (최근 30일)
Hello,
in Simulink I have a vector V = [1 0 2 1]. I make a calculation to know which of those four values I have to change. Then, how can I only modify one of those values?
The subprogram sequence is like this:
  • Read vector V
  • Calculate index to be changed = X
  • Change index X in vector V
  • Read vector V
  • Calculate index to be changed = Y
  • Change index Y in vector V
  • ...
If I could save the index in to a variable and then use it on the "Overwrite Values" block it will be done. But I don't know how to do it.
Other way to get my problem done will be using something similar to an "Index Vector", but instead of several inputs an one output, one input and several selectionable outputs.
Many thanks! Daniel.

채택된 답변

Ryan G
Ryan G 2012년 11월 5일
편집: Ryan G 2012년 11월 5일
Picking apart vectors can be a little tough in Simulink with only blocks. Fortunately, Simulink is built on MATLAB and that gives you a lot of options.
You can follow Jose-Luis' advice using a MATLAB Function block. This operation would support code generation and after it creates the mex-file for the function the first time it will not need to generate code again.
  댓글 수: 1
Dani Tormo
Dani Tormo 2012년 11월 6일
Yes, it works. But I want to know if there were other easy way to deal with matrix and vectors, but Matlab isn't LabView.
Anyway, many thanks for your reply!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Attributes and Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by