fprint f help with printing a list

8 次查看(过去 30 天)
i am trying to make a fprintf line to display like the attatched screenshot below based on the code below
function x = Xsection(type)
switch type
case 1 % Benchmark
x = [ 0, 0;...
200, 0;...
200, 25;...
25, 25;...
25,200;...
0 ,200;...
0 , 0];
end
end

回答(1 个)

Adam Danz
Adam Danz 2021-9-29
编辑:Adam Danz 2021-9-30
In Matlab R2021a or later, you can use formattedDisplayText() to convert the matrix to a string. See this community highlight for further demos.
x = randi(20,5,2)
x = 5×2
12 20 12 16 9 6 3 1 9 17
fprintf('%s',formattedDisplayText(x))
12 20 12 16 9 6 3 1 9 17
Prior to Matlab R2021a,
fprintf('%s',evalc('disp(x)'))
12 20 12 16 9 6 3 1 9 17
  5 个评论
Adam Danz
Adam Danz 2021-9-30
I've updated my answer to include a solution that works prior to R2021a.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by