Add line plot to saved figure
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I had this figure (.fig file) I had saved months ago, and I wanted to add an extra line plot to it, but it seems that I have deleted the script with which I had actually calculated the values of the plotted vectors. Since I still have the .fig file though, I was wondering if it would be possible to add a plot line to it, or otherwise extract the values of the already plotted vectors back into a matlab variable so I could re-plot them. I am really inexperienced with image related commands in matlab so I had a quick look at print and imwrite commands but they do not seem to cover .fig files.
Any advice will be appreciated. In the worst case I'll just have to write the script again. Thanks in advance.
0 Kommentare
Antworten (1)
nick
am 17 Apr. 2025
Hello sirona,
To add a new line to the existing .FIG file, you can follow these steps:
% Create some data
x1 = 0:0.1:10;
y1 = sin(x1);
figure;
plot(x1, y1, 'b-', 'LineWidth', 2);
title('Original Plot');
xlabel('X-axis');
ylabel('Y-axis');
saveas(gcf, 'example_figure.fig');
% Close the figure
close(gcf);
%%
% Step 1: Open the existing figure
fig = openfig('example_figure.fig', 'reuse'); % 'reuse' opens it in the same window
% Step 2: Get the current axes
ax = gca;
% Step 3: Add a new plot
hold(ax, 'on');
x_new = 1:10;
y_new = rand(1, 10);
plot(ax, x_new, y_new, 'r-', 'LineWidth', 2); % Add new plot
% Step 4: Save the updated figure if needed
savefig(fig, 'updated_figure.fig');
Kindly refer to the documetation by executing the following command in MATLAB Command Window to know more about 'openfig' function :
doc openfig
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!