0

i want to plot some data by using Simulink Scope, here is my simplified Simulink model: enter image description here

and there are my code in the MATLAB Function Block:

1. function pCO2_a = Oxy(Qg)
2.
3. coder.extrinsic('testWQ');
4.
5. pCO2_a = zeros(41,1);
6. pCO2_a = testWQ();
7. end

what am i trying to call is another ode function:

1. function y = testWQ
2. 
3. Qg = 3;
4. tspan = [0 5];
5. y0 = 0;
6. [t, Y] = ode45(@f,tspan,y0);
7. y = Y(:,1);
8.
9.    function dydt = f(t,y)
10.       dydt = Qg*t;
11.    end
12.
13. end

And then i ran my Simulink model, in the Scope will of course show many horizontal lines instead of one line with time. I know the reason is because pCO2_a = testWQ() will get double data, but is there any way i can still get the right diagram with this data in Scope?

  • I am not sure if that is the problem, but you can change the type of data inside the function so you return whichever type you preffer. – Ander Biguri Feb 20 '20 at 13:28
  • Tried as you said, but it sadly doesn't work. But still thank you for your suggestion. @ AnderBiguri – wenqing qiu Feb 20 '20 at 13:57

1 Answers1

0

A quick look tells me that it seems to be possible to make a model for this using simulink blocks and not a matlab function. Is this model you showed part of a bigger model? If not than doing this the way you are makes no sense in Simulink, you could've just used Matlab.

If it is then Simulink will plot many lines since you output a vector. Any input to a Scope that is a vector is treated as different variables having a certain value at time t, so to say. What you seem to be doing is a simulation in a simulation. The scope does not know this of course.

To my knowledge there is no way to plot the whole time sequence for that variable as one line in the scope in the way you want to.

You could for instance only output the last value of the vector then you will get a smooth line over time, however, missing the in between points which you did obtain in your mini-simulation.

EDIT: I just came across this: the array plot block. However, this can only plot the current input, so the plot updates every simulation step. It allows you to plot the intermediate simulation result from testWQ at time step t.

Nathan
  • 391
  • 1
  • 6