Hi
I would like to create a vector in script lua like this: A = 0:0.1:1. It means A starts from 0 and stops at 1 by step 0.1. To create this vector in Lua, I used the following code:
A = {}
function init(model, par)
end
function update(model)
local start = 0
local stop = 1
local step = 0.1
for i = start, stop, step do
A[#A + 1] = i
end
end
function store_data(frame)
frame:set_value("A", A)
end
However, A is zero in Analysis plots as following picture. Would you help me how to correct it? (A is Rtime )
Best
Vector
- Thomas Geijtenbeek
- Posts: 437
- Joined: Wed Mar 12, 2014 8:08 am
Re: Vector
A seems to be a table, so you can't do frame:set_value("A", A).
function update(model, timestamp) is called every frame, so perhaps use timestamp to compute A?
If A is meant to be a constant array of increasing numbers, then you should compute it in init() and not in update().
function update(model, timestamp) is called every frame, so perhaps use timestamp to compute A?
If A is meant to be a constant array of increasing numbers, then you should compute it in init() and not in update().
- Samane Amini
- Posts: 101
- Joined: Sun Jan 12, 2020 3:48 am
Re: Vector
Many Thanks Thomas for your quick reply.
May you tell me how to call A in form of a table?
I changed my main code to ask my question. In fact, I want to obtain the length of time vector at instance time. So by having time step, I create this vector to record time. In this case we have:
function update(model)
t = model:time()
local start = 0
local stop = t
local step = 0.01
for i = start, stop, step do
A[#A + 1] = i
end
end
Do you think my way is correct? or you have other solution?
Best
May you tell me how to call A in form of a table?
I changed my main code to ask my question. In fact, I want to obtain the length of time vector at instance time. So by having time step, I create this vector to record time. In this case we have:
function update(model)
t = model:time()
local start = 0
local stop = t
local step = 0.01
for i = start, stop, step do
A[#A + 1] = i
end
end
Do you think my way is correct? or you have other solution?
Best