How to pass required data for generating a figure between functions?

5 次查看(过去 30 天)
I have a main script that runs a series of test functions. (The specific test sereis may depend on the type of input data.)
The main script is generic, so that more new test functions can be added in the future.
For example:
T1 = test1(input_data);
T2 = test2(input_data);
T3 = tets3(input_data);
T4 = tets4(input_data);
Each test function analysis input data, and generates test results in two forms: 1. Numeric data, 2. Data for a graphic figure.
The main script receives all of the test results from all of the test functions and summarizes it. All of the graphic data is than used to generate a summarizing figure.
I do not need the individual test functions to actually open a figure, I only need to pass all the graphic data required to build a figure later on.
Since some of the graphics are quit complex, and not a straight forward simple plot(x,y), I would like the test functions to generate a graphics object that contains all the data that can be easily passed between functions and can be ploted in a single command.
I conciderd generating figures within the individual test functions, but this doesn't seem like good practice, since figures can be run over by mistake, and if a figure is closed all the data is lost.
I also tried building a ploting function handle within the individual test function that contains all the data, this handle can be passed back to the main script and can later be ploted easily.
function[T1] = test1(input_data)
x = input_data;
y = input_data.^2;
T1.graphic = @() plotTest1(x,y)
T1.x = x;
T1.y = y;
end
function[] = plotTest1(x,y)
plot(x,y)
title('Title')
xlabel('xlabel')
ylabel('ylabel')
end
However this method is also not ideal, for instance, unlike other variables, saving the handle will not save the data.
Another approach is to generate the figures within the test functions, save them as fig files and and use the fig files as globel variables...
I guess I am looking for a way to save graphic data just like other variables to the workspace so that they can be easily passed on to other functions and can easily be ploted later on.
Thanks,
Yaakov

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品


版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by