필터 지우기
필터 지우기

(simulink beginner) : cannot load a time series from workspace

조회 수: 5 (최근 30일)
N/A
N/A 2012년 9월 30일
Hi all,
I am trying to figure out how to make some simple things work in Simulink. For example I have a matlab function which computes the position of an object given it's previous position and its velocity, as follows:
function [xnew vnew] = miModel(x,v,dt)
% x is the current position
% v is the current velocity
xnew = x + dt*velocity; % xnew is the new position
vnew = v; % new velocity =v in this example
end
I want to load the 'velocity' variable from workspace, using the 'FromWorkspace' block. I define the velocity variable in the required structure as follows:
velocity.time = [linspace(0,1,100)]'; % 100
velocity.signals.values = [0*ones(50,1); 1*ones(50,1)] ;
velocity.signals.dimensions = [1];
I construct my model as shown below..
or here for a fullsize image:
when I run the simulation, it does not read the values I provide;i.e., first 50 iterations with velocity 0, and the other 50 with velocity =1; Please note that I am using a simple model in 1-D (velocity and position on x-axis only). Also, since I am working in discrete time, I set my solver to 'discrete' with fixed step = 1;
Any ideas? Many thanks...from a simulink beginner M

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 30일
편집: Azzi Abdelmalek 2012년 9월 30일
how to set a variable from workspace
time=0:0.1:10
signal=sin(t)
variable=[time;signal]'
  댓글 수: 7
N/A
N/A 2012년 10월 1일
편집: N/A 2012년 10월 1일
Hi Azzi, Thanks again for your replies (and patience!)
  1. For 1) Thanks! I was not aware I could literally use 'max(time)' in stop time box.
  2. For 2) I need a little bit more clarification; (please let me know if my understanding of what you suggest is not right) My reasoning is that my real data will be coming in at high frequency, and I do not want to have a step as short as the period of the data input rate. Therefore, if you look at the diagram I have above,as an input to my block I have a constant 'dt'; this is the simulation time of each block, which as you suggest should be the same as the Fixed-step size in the solver!
So for 2), to do it on every block, (if i understood correctly) I was wondering whether it is possible to have a 'global constant : dt', and each block should read from that global constant this fixed time-step (sampling time). Also as the fixed-step size in the solver I should put 'dt' ...
thanks again M
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 1일
yes, since you are handling a discret process, it is better if you control the sample time. you have just to set all sample time blocks to ts, in workspace or m file you set ts= what you want.

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

추가 답변 (1개)

N/A
N/A 2012년 9월 30일
OK: I spotted the problem :
I was using :
velocity.time = [linspace(0,1,100)]';
And my simulation time was from 0: 200 with a time step =1, which means it will use inputs at time 0,1,2... therefore all good!
Thanks Azzi for the response anyway.
M

Community Treasure Hunt

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

Start Hunting!

Translated by