Problem with MATLAB Function block in Simulink

15 Ansichten (letzte 30 Tage)
Alex Brissette
Alex Brissette am 1 Mär. 2011
I'd like to export data generated in Simulink to the Matlab workspace by using a Matlab function that writes the data to a variable in the workspace. Not very efficient, but necessary for my purposes. The problem is that the value passed into the Matlab Fcn block is sometimes incorrect, even wildly inaccurate. I placed a display block in parallel with the Matlab Fcn block and, occasionally, the displayed value does not match the value inside the function code (observed while debugging). Any clues to why this is happening?
Alternatively, is there a way to use a variable inside a structure as the target of the Simulink To Workspace block? Simulink won't allow the "structure.field" syntax as the To Workspace variable name.
Thanks!
  1 Kommentar
RICHARD ALEXANDER CÓRDOVA HERRERA
Bearbeitet: RICHARD ALEXANDER CÓRDOVA HERRERA am 24 Mai 2020
Hi Alex! I am working in a project and i got this issue. I need to process the data in real time, but the data from the Matlab Function Block is sometimes diferent than the simulink. I put a scope too, and verify this. Did you solve this?
I can use a filter, but sometimes I have very large peaks and it does not work.
Richard

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Sebastian
Sebastian am 2 Mär. 2011
The "To Workspace" block is indeed not able to write directly into some structure. If you need the data as part of the structure after your simulation finished, you could use To Workspace blocks, write to individual variables and then use the model's StopFcn callback to post-process, move the data to your structure and clean up. If you need the data in your structure while the simulation runs, then the To Workspace block does not help as it buffers the data till the end of the simulation. In that case using a MATLAB Fcn block might be a valid way, I would prefer to use a simple MATLAB code S-Function though, because it offers more flexibility. The following link shows an example how this might look like: http://www.mathworks.com/support/solutions/en/data/1-1AY2H/index.html

Kaustubha Govind
Kaustubha Govind am 2 Mär. 2011
Addressing the inconsistency between the values seen in the MATLAB Fcn block and the Display block: Could this be because of the order of execution of the two blocks? If the Display block is executed after the MATLAB Fcn block, then what you see on the Display block while debugging is probably the value from the previous time-step. You can verify this by one of two ways:
  1. Display and examine the Sorted Order.
  2. Use a From Workspace block to log the signal and at the end of the simulation, compare the values written by your MATLAB fcn block and the From Workspace block.
  1 Kommentar
Alex Brissette
Alex Brissette am 2 Mär. 2011
I think I see what you're saying, and I don't think execution order is the problem. I also connected a scope and a To Workspace block to the signal, and they recorded the values I expected. The array generated by the function code was not at all consistent with the other measurements, which agreed with each other.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by