필터 지우기
필터 지우기

Extract data from fig file and redraw the plot

조회 수: 15 (최근 30일)
Venkatkumar Muneeswaran
Venkatkumar Muneeswaran 2023년 6월 26일
댓글: Deep 2023년 6월 26일
Hello
How to extract the data from the attached fig file into the workspace as variable and redraw the plot again.
Could anyone please help me resolve the issue?

채택된 답변

Deep
Deep 2023년 6월 26일
Hi, this will extract the data of the 4 lines from the .fig file and store them in XData and YData. The code should be self explanatory.
open('untitled.fig');
% Get the current figure and its children
f = gcf;
axes = f.Children;
% Initialize XData and YData as cell arrays
XData = {};
YData = {};
% Loop through the axes
for a = 1:length(axes)
ax = axes(a);
% Loop through the axes children
for i = 1:length(ax.Children)
% Check if the current child is a line object
if isa(ax.Children(i), 'matlab.graphics.chart.primitive.Line')
XData{end+1} = ax.Children(i).XData;
YData{end+1} = ax.Children(i).YData;
end
end
end
close(gcf);
disp(YData(1)); % Display the current values for the 1st line
  댓글 수: 2
Venkatkumar Muneeswaran
Venkatkumar Muneeswaran 2023년 6월 26일
편집: Venkatkumar Muneeswaran 2023년 6월 26일
Hi @Deep, Thanks for the code .
I need to Plot XData(1), YData(1)
figure()
plot(XData(1),YData(1));
How to do this?
Deep
Deep 2023년 6월 26일
You'll need to convert the cell to an ordinary array.
x = cell2mat(XData(1));
y = cell2mat(YData(1));
plot(x, y);
If the answer helps, please approve it :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by