how can I see the x and y value table from an equation on matlab

15 次查看(过去 30 天)
x = 0:50:50;
y1 = 4*x;
y2= 100-4*x;
plot(x,y1,'g',x,y2,'b')
grid on
this allows me to plot the data
but I want to be able to see the value of y at some x, in some sort of chart or list

回答(1 个)

fred  ssemwogerere
fred ssemwogerere 2020-2-12
Hello, you could create a table from your variables using table
Tbl=table(x',y1',y2','VariableNames',{'x','y1','y2'});
In case you want the list or table added to your plot, you could make use of annotation. (but this may be better suited to addition of simpler text not table). Something like this;
% First convert table to cell.
Tbl_cl=table2cell(Tbl);
% vertical concantenate table variable names with its values and convert to a string
Tbl_str=string([Tbl.Properties.VariableNames;Tbl_cl]);
% set the x,y,width, and height (in that order) of a text box to be added to the plot for example;
txtdim=[.5 .5 .1 .1];
% add annotation to the plot specifying the string input argument as character array ("char(Tbl_str)")
an=annotation('textbox',txtdim,'String',char(Tbl_str),'FitBoxToText','on');
For a more robust option to show text or your data in same graphics window, you could search in the documentation about uitable and annotation, or you could also refer to the link below:

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by