Output of a Function in a graph and table

I have a set of functions that I need to express as a graph as well as show the data in a table in separate figures. How do I go about this? The disp function did not work out nor is using the basic 'table' code since it requires data to already be there. Thank you for your help!

7 Comments

No idea what you're trying to accomplish, specifically, sorry...
At least show a function and some represeantion of what is the issue you ran into when you tried to solve the problem.
Of course a table has to be populated with something -- how would you show anything otherwise???
Have you tried ezplot for a start?
This is more of a concept based question. For the sake of an example, let us say there are 2 functions:
y = x1
y = x1^2 + x2
We can easily plot both on the same graph, but how can we also obtain a figure of the data table such that we can see the actual data, like:
y x1 x2
0 0 0
1 1 1
Is this both y?
y = x1;
y = x1^2 + x2
my apologies, the system should be:
y1= x y2=x^2
please note that this is just an example, I am trying to understand the conceptual code. thank you very much for your help!
"obtain a figure of the data table such that we can see the actual data, like:"
Where do you want this? There's the variable editor/viewer or you can evaluate the function(s) for a set of x and disp them something like
disp([y x1 x2])
or put them into a table
table(y,x1,x2)
which brings along a variable name header or you can write them out in whatever format you wish w/
fmt=[repmat('%05.2f',1,3) '\n'];
fprintf(1,[y x1 x2].')
It still really isn't at all clear just what you're trying to accomplish for what purpose.
All I am really trying to accomplish is that when I plot a set of functions, I also obtain a table with the independent and dependent variables. ex:
y1 = x^2
y2 = x^3
y3 = x^4
plot( x, y1)
hold on
plot( x, y2)
hold on
plot(x,y3)
hold off
xlabel('area available for bacteria growth');
ylabel('concentration of bacteria');
legend('y1=bacteria1', 'y2=bacteria2', y3=bacteria3');
Then when this is run, a graph pops up. I am seeking a code (table, fprintf, etc) that will also have a figure of the correstponding values of the inputs and outputs for a range of x-values.
Thank you all for your help!
Look at uitable or the text function, perhaps...

Sign in to comment.

 Accepted Answer

Something like that?
Table.PNG
I ended up doing it pretty quick just to get the idea to solution since I'm not 100% of what you're wanting. The idea here is to create a figure, use the subplot to plot the graph and use uitable to plot the table..
% Example of a Dataset (Matrix)
ExAr = randi(100,20,8);
% Get size of the screen to make determinate the size of the window
Size = get(0,'ScreenSize');
Mx = Size(3)/2;
My = Size(3)/2;
Fig_left = Mx/2;
Fig_bott = My/4;
Fig_width = Mx;
Fig_height = My/2;
% Create Figure with Postion, Title and resize off
f = figure('Name','Data Plot', 'NumberTitle','off', ...
'Position',[Fig_left Fig_bott Fig_width Fig_height], 'Resize','off');
% Create Table on the left side of the figure
uit = uitable(f,'Data',ExAr,'Position',[1 1 Fig_height (Fig_width/2)]);
% Create Plot on the right side of the figure
s1 = subplot(1,2,2);
plot(ExAr(1,:),ExAr(3,:))
If you get the idea behinde it you can change and adapt it for your problem..
Hope it helps!

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 27 May 2019

Answered:

MSP
on 30 May 2019

Community Treasure Hunt

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

Start Hunting!