How to display a table in the command window?

In my previous question ( http://www.mathworks.nl/matlabcentral/answers/69224-how-to-write-a-function-that-generates-a-hyperlink-that-runs-a-function ) I learned to display a list of hyperlinks in the command window, but now I would like to display them in a table with two columns and 4 rows (one for every integration method). I already found soms things on the internet to make a table:
tabel = ModelAdvisor.Table(2,4);
setHeading(tabel, 'All the methods to calculate integrals');
setHeadingAlign(tabel, 'center');
setRowHeading(tabel, 1, 'With graph');
setRowHeadingAlign(tabel, 1, 'center');
setRowHeading(tabel, 2, 'Without graph');
setRowHeadingAlign(tabel, 2, 'center');
The problem is that I don't understand how I can actually edit information, namely hyperlinks (see previous question), in the tabel.
Can someone help me?
-----
Edit: I'll be a bit more specific. I implemented 3 methods to approximate the integral of a function: riemann_Uf, riemann_Lf and trapezoid. Each method has 2 variants: a function that only calculates the integral (name of the function ends with _exgr) and another function that also draws the graph of the function (name ends with _ingr). For the drawing of the graph, I wrote a function integral_graph. Every function needs 4 arguments: f, a, b and n (see previous question). When one calls the function integral with these arguments, I'd like a table to be displayed in the command window looking like this:
*With graph* *Without graph*
Riemann Uf Riemann Uf
Riemann Lf Riemann Lf
Trapezoid's Rule Trapezoid's Rule
Where clicking on for exemple Riemann Uf in the first column runs the function riemann_Uf_ingr(f,a,b,n) and clicking on Trapezoid's Rule in the second column calls the function trapezoid_exgr(f,a,b,n).

 채택된 답변

Walter Roberson
Walter Roberson 2013년 3월 31일

1 개 추천

Example:
syms x
f{1} = x^2 + sin(x);
cw1 = 10; %width of column #1
cw2 = 12; %width of column #2
lb = 3; ub = pi; n = 50;
ftable = { 'riemann', 'Riemann'; 'trapezoid', 'Trapezoid' };
fvals = [17.3; -4.2]; %numeric values for table
graphit = true;
fprintf('With graph\n');
for K = 1 : size(ftable, 1)
fstr = sprintf( 'sym(''%s'')', char(f{1}));
fcall = sprintf('%s(%s,%f,%f,%d,%d)', ftable{K,1}, fstr, lb, ub, n, graphit);
fprintf('<matlab:%s %*s> %*g\n', fcall, cw1, ftable{K,2}, cw2, fvals(K));
end

댓글 수: 8

Jeroen
Jeroen 2013년 3월 31일
Thank you for your answer. Like last time, this is a step in the right direction, but it doesn't solve my problem entirely. I updated my question with some more information about what I'd like to accomplish.
Hint:
[ftable{K,1} '_exgr']
Jeroen
Jeroen 2013년 3월 31일
Okay, but do I still have to use all those 'set' operators I already found?
No.
Jeroen
Jeroen 2013년 3월 31일
편집: Jeroen 2013년 3월 31일
My code looks like this at the moment:
function [ ] = integraal( f,a,b,n )
functies={'Riemann Lf'; 'Trapezium'};
tabel = {'riemann_Lf_ingr', 'riemann_Lf_exgr';
'trapezium_ingr', 'trapezium_exgr'};
fprintf(['Berekening met grafiek', ' ','Berekening zonder grafiek\n\n']);
for i = 1 : length(tabel)
str = sprintf( 'sym(''%s'')', char(f));
kolom1 = sprintf('%s(%s,%g,%g,%d)', tabel{i,1}, str, a, b, n);
kolom2 = sprintf('%s(%s,%g,%g,%d)', tabel{i,2}, str, a, b, n);
fprintf('<matlab:%s %s>', kolom1, functies{i,1});
fprintf(' ');
fprintf('<matlab:%s %s>\n', kolom2, functies{i,1});
end
fprintf('\n\n');
end
When clicking the functions, they run properly, so that part of my problem is fixed. Now, I'd like to correctly implement the distance between the hyperlinks in the columns. As you can see in my code, I displayed some spaces at the moment, but of course, depending on the length of the first hyperlink, the hyperlinks in the second column are outlined differently.
Is there a way to display the hyperlinks at the left (or in the center) of the corresponding columns?
For left justification, provided that you do not mind the hyperlink continuing to the end of the column:
hlwid = 15; %for example
fprintf('<matlab:%s %-*s>', kolom1, hlwid, functies{i,1});
If underlining the rest of the link is not acceptable then,
fprintf('<matlab:%s %s>%s', kolom1, functies{i,1}, blanks(hlwid - length(functies{i,1})) );
Jeroen
Jeroen 2013년 4월 1일
Mission table accomplished! Thanks for all the help, Walter!
Do you know how to export this table as pdf or png?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by