フィルターのクリア

from figure file to mat file?

48 ビュー (過去 30 日間)
MementoMori
MementoMori 2023 年 4 月 6 日
コメント済み: MementoMori 2023 年 4 月 12 日
Hi, I have saved a fig file and now I want to do some operation on it. I have tried
example=load("name.fig",'-mat');
but it doesn't give me a mat file.
Do you know how to convert?

回答 (1 件)

Mathieu NOE
Mathieu NOE 2023 年 4 月 6 日
hello
you can use that function to extract data from figures
function data = extract_data_from_figures(filename)
%%
%
% Input : File name <filename.fig>
% with multiple plots in a single file
% Output : struct data
% : data.names contains names of the display object Yvalues
% : data.Y contains the actual plot values withthe first column
% containing the x-values
%
% Written by Chetanya Puri, 2019
% Last Modified: Nov 6, 2019
%
fig = openfig(filename); % Open figure and assign it to fig object
dataObjs = findobj(fig,'-property','YData'); % Find all graphic objects with YData, in our case line values
xval = dataObjs(1).XData; % Find the X-axis value
Ymat = [xval(:)]; % Create a matrix with first column of x values
for i=1:length(dataObjs)
legend_name{i,1} = dataObjs(i).DisplayName;
yval = dataObjs(i).YData;
Ymat = [Ymat yval(:)]; % Keep appending column vectors
end
close(fig); % close the figure
data.names = ['X';legend_name];
data.Y = Ymat;
end
  4 件のコメント
Walter Roberson
Walter Roberson 2023 年 4 月 12 日
for i=1:length(dataObjs)
if isprop(dataObjs(i), 'DisplayName')
legend_name{i,1} = dataObjs(i).DisplayName;
else
legend_name{i,1} = sprintf('%s: #%d', classname(dataObjs(i)), i);
end
yval = dataObjs(i).YData;
Ymat = [Ymat yval(:)]; % Keep appending column vectors
end
MementoMori
MementoMori 2023 年 4 月 12 日
@Walter Roberson thank you. It gives me this error by the way
Undefined function 'classname' for input arguments of type 'matlab.graphics.primitive.Image'.
Error in extract_data_from_figures (line 22)
legend_name{i,1} = sprintf('%s: #%d', classname(dataObjs(i)), i);
Error in NuovaDisposizione (line 295)
data=extract_data_from_figures(filename);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by