Reputation: 1660
I have a cycle in Fortran, and I would like to call a Matlab script that at each iteration simply plots the 2 variables I am computing, always in the same figure, in a way that I can see how my solution evolves in time (basically a video)
do i=1,n
Y(1:m) = blabla
X(1:M) = blabla
write X and Y on file
RUN a matlab script which reads file and plots X and Y
enddo
If there is a way to bypass writing on the file and I can pass the variables as an argument even better cause it will be more efficient (I doubt it is possible). Basically, I want the results plotted in real-time so I can catch if the solution is unstable without having to wait until the end of the simulation.
Upvotes: 2
Views: 218
Reputation: 4767
*Just something that might be useful (feel free to edit and build upon this)
An animated plot may help with the video like plotting that occurs within the same figure. I tried to push as much as I could into a function. No clue how to achieve passing variables to the MATLAB script from Fortran (will look into it).
But if you were willing to calculate all the points first and then pass them to MATLAB to be animated this might help (a caveat is that this wouldn't have that real-time timing when the data is calculated and immediately passed for plotting).
clf;
Animated_Plot = animatedline;
for x = 0: +1: 100
y = 0.5*x;
Add_Data_Points(x,y,Animated_Plot);
end
function [] = Add_Data_Points(x,y,Animated_Plot)
hold on
addpoints(Animated_Plot, x, y);
drawnow
axis([0 100 0 100]);
xlabel("x"); ylabel("y");
end
Ran using MATLAB R2019b
Upvotes: 2