MATLAB Answers

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

128 views (last 30 days)
Emily  Vasquez
Emily Vasquez on 11 Feb 2020
Answered: fred ssemwogerere on 12 Feb 2020
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

  0 Comments

Sign in to comment.

Answers (1)

fred  ssemwogerere
fred ssemwogerere on 12 Feb 2020
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:

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!