- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » How can I plot arrays?
How can I plot arrays?
How can I plot arrays?
Hi together,
I work with arrays and would like to plot some simulation results. For example I have the voltage array V[x]:
V[10]:=1:10;
It represents the voltage as function of the space index x. Each local voltage V[x] depends on the time.
I also have a second array J[x]:
J[10]:=2:20;
How can i plot V[x] as function of J[x] for a specific time?
I would need something like
Vend[:] = val(V[:],1)
Jend[:] = val(J[:],1)
plotArray(Vend[:], Jend[:])
Sunny regards,
Stefan
Re: How can I plot arrays?
You can do this by post-processing in matlab/octave. Probably also scilab.
- sjoelund.se
- 1700 Posts
Re: How can I plot arrays?
Ok, so I guess it is not possible in OpenModelica.
There is a Matlab-OpenModelica Interface to import the *.mat files:
http://www.mathworks.com/matlabcentral/ … -interface
However, it is quite old and does not work with the current version of OpenModelica.
If there is a solution that works with arrays and with the current version of OpenModelica, please let me know.
Re: How can I plot arrays?
Hi,
OpenModelica generates Model_res.mat files on simulate(Model)
so I guess you can just import those in Matlab and play with them
there.
Cheers,
Adrian Pop/
- adrpo
- 885 Posts
Re: How can I plot arrays?
Thank you for your reply. However, it does not give new information.
Anyway, I would still prever a solution that works inside OpenModelica. Maybe it is possible
to transform the array data at a certain time in a dummy variable?
V[x,t=1] = > V_dummy[t*],
J[x,t=1] = > J_dummy[t*],
plotParametric(V_dummy,J_dummy) ???
Re: How can I plot arrays?
Here is how it works:
function array2time
//this function gets an array of data and the time
//it returns a time dependend stepwise result
//each array value corresponds to a specific time interval
input Real array[:];
input Real time;
output Real result;
protected
Integer array_length;
Real delta_time;
Real stop_time;
algorithm
stop_time:= 1;
array_length := size(array,1); //number of values
delta_time:=stop_time/(array_length-1); //size of time interval
for k in 1:array_length loop
if time >delta_time*(k-1)-delta_time/2 and time <= delta_time*k-delta_time/2 then
result:=array[k];
end if;
end for;
//if time >=stop_time-delta_time/2 then
// result:=array[array_length-1];
//end if;
end array2time;
model test
//this model shows a work around to plot arrays in modelica
//define some arrays
constant Real V_array[:]={ 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.55, 0.6};
constant Real J_array[:]={ -30, -29.8, -29.5, -29, -26, -15, 5, 30};
//define some variables that will hold the array data
Real V;
Real J;
equation
//transform array data to time data
V = array2time(V_array,time);
J = array2time(J_array,time);
end test;
simulate(test);
plotParametric(V,J)
plot(V)
plot(J)
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » How can I plot arrays?