Why can´t i do this? (C-Code doubt)

Hello,
If i have as a S-Function parameter:
variable1 (with value 0)
And i have an input (u) and an output (y). I want to do this:
double variable3 = 0,*var,*input,*last;
input = &u[0]; /* u[0] is the Simulink block input */
last = &variable1;
var = &variable3;
*var = *input - *last;
if (variable3 > 0){
y[0] = *input; /* y[0] is the Simulink block output */
*last = *input; ---> This line doesn´t work!, Why?
}
else
y[0]=0;
I´m trying to implement this code in a S-Function.
Thanks!

3 件のコメント

Jan
Jan 2012 年 10 月 7 日
What does "doesn'twork" mean? Do you get a warning from the compiler? If so, which one?
Enrique
Enrique 2012 年 10 月 7 日
I don´t get any error or warning. The problem is the variable *last, it doesn´t get the value of *input.
Friedrich
Friedrich 2012 年 10 月 8 日
Are you sure you get in the if branch? maybe add some ssPrintf statements to get some runtime debugging outputs.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2012 年 10 月 7 日

0 投票

Is u a const variable, while last is not?

3 件のコメント

Enrique
Enrique 2012 年 10 月 7 日
How can i change the data type of last?
I try to do:
double * const last;
But i have this error:
error C2166: l-value specifies const object
In the line:
last = &variable1;
Thanks!
Jan
Jan 2012 年 10 月 8 日
Nope, than the const qualifier is most likely not the problem.
How do you check, that *last is not assigned correctly? I'm convinced that the line does assign the value. Therefore I assume, that you expect the changes on the wrong place.
Enrique
Enrique 2012 年 10 月 8 日
I see the values creating an another output and this output linked to a "To Workspace" block.
The variable *last always is 0.
Thanks!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

製品

タグ

質問済み:

2012 年 10 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by