How can I use calculated value

3 次查看(过去 30 天)
Hello ,
I just started MATLAB Simule and I have a question. I have a constant value and use it in a function. I want to use function output instead of my constant value?
Someone can give me a hint?
Thank you

采纳的回答

Jim Riggs
Jim Riggs 2018-3-10
编辑:Jim Riggs 2018-3-10
I think that the reason that no one has offered an answer to your question for the last 20 hours is, in part, because the question is unclear, but i am going to take a guess: It could be that this is what you mean:
Or maybe this:
These are reasonable guesses based on the stated desire to use "function output". However, it may be that you want to replace the constant with a calculation? (This would not be considered a "function") In that case, you can simply put the calculation in the constant block, and define any variables used in the calculation in the Matlab workspace before you run the model.
If you give more information in your question you will get better help. For example, state the actual function calculation you want to use in place of the constant, and it will be more clear.
  2 个评论
Metehan AYTAC
Metehan AYTAC 2018-3-10
I want to use Constant value once.After that use y instead of constant. Sorry for my bad description.
Jim Riggs
Jim Riggs 2018-3-11
编辑:Jim Riggs 2018-3-11
Here is how to do that. You use a "Switch" block to select between two signals. The first signal (on top) is the constant initial condition. The second signal (on the bottom) is the output from your function block. The middle port is the switch logic. The switch is triggered by the switch signal being compared to zero. When this middle signal is greater than zero, the top signal is selected. When the switch signal is less than or equal to zero, the botom signal is selected. Now you set up a switch signal that will be "1" for the first itteration, and "-1" for every other itteration. This is done using a constant block with "-1" value, and a memory block.
The output of the memory block is delayed by 1 iteration. Inside the memory block, set the "initial condition" to +1. This will make the output of the Memory block "1" on the first pass, and then it will pass the value of the input constant (-1) for all subsequent passes, so you have a signal series that is +1, -1, -1, -1, ...etc. This triggers the switch block to use the top signal for the first pass, and the bottom signal for all subsequent passes.
Another way to do the same thing is:
The "memory" block must have an initial condition set to +1 (actually, any positive value will do)

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by