Updating Plot "On the Fly" with MATLAB

  • MATLAB
  • Thread starter Euclid
  • Start date
  • Tags
    Matlab Plot
In summary, the conversation discusses the difficulty of creating a function that can update a plot "on the fly" in MATLAB. The speaker is trying to find a way to update the plot as soon as a single pixel changes, but has been unsuccessful so far. They mention using the "figure" command and the "drawnow" function, but both options have drawbacks. Ultimately, there is no easy solution for this task and it may require communication with the developers.
  • #1
Euclid
214
0
I am trying to write a function that will update a plot "on the fly". For instance, in the test function:
function colorplot
x = ones(100,100);
for i = 1:100
for j = 1:100
x(i,j)=uint8(255^((i+j)/200));
image(x); colormap(gray)
end
end
MATLAB will run the entire function before displaying the image in the matrix x. I want to get MATLAB to update the plot as soon as it changes a single pixel (or more generally, whenever I tell it to!). Does anyone know how to do this? The only way I have been able to close to getting this to happen is to use the "figure" command right before "image", but this just generates 100*100 images when I only want 1.

UPDATE: I found a function drawnow which performs what I want the plot to do, but it is extremely slow. drawnow redraws the whole plot but I am only updating a few pixels. Any ideas?
 
Last edited:
Physics news on Phys.org
  • #2
This is not an easy task, and there is (to the best of my knowledge) no inbuilt function for this. You are asking for a function that will find the portion of the image that has been changed/updated, and change only that portion. I doubt whether something like that actually exists. I have seen Matlab redraw the plots/figures rather than change portions, not update previous plots. Maybe this can be communicated to the developers.
 

What is updating plot "on the fly" in MATLAB?

Updating plot "on the fly" in MATLAB refers to the process of continuously updating a plot as new data is added or changed, without having to re-run the entire code. This allows for real-time visualization of data and is commonly used in scientific and engineering applications.

How do I update a plot "on the fly" in MATLAB?

To update a plot "on the fly" in MATLAB, you can use the "hold on" command to prevent the plot from being cleared each time new data is added. Then, use the "plot" command to add the new data points to the existing plot. Finally, use the "drawnow" command to update the plot window and display the changes.

Can I update multiple plots "on the fly" in MATLAB?

Yes, you can update multiple plots "on the fly" in MATLAB by using the "subplot" command to create multiple plot windows and then updating each plot separately using the steps mentioned above.

What are the advantages of updating plots "on the fly" in MATLAB?

Updating plots "on the fly" in MATLAB allows for real-time visualization of data, which can be useful for monitoring and analyzing data in real-time. It also saves time by not having to re-run the entire code each time new data is added, making it more efficient for large datasets.

Are there any limitations to updating plots "on the fly" in MATLAB?

One limitation of updating plots "on the fly" in MATLAB is that it can be memory-intensive, especially for large datasets. Additionally, if the code is not written properly, it can lead to errors or unexpected results. It is important to carefully manage the memory and code structure when using this technique.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
905
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
565
Back
Top