fprint f help with printing a list

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

Antworten (1)

Adam Danz
Adam Danz am 29 Sep. 2021
Bearbeitet: Adam Danz am 30 Sep. 2021

0 Stimmen

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 Kommentare

Joseph Catanese
Joseph Catanese am 29 Sep. 2021
this didnt work
Joseph Catanese
Joseph Catanese am 29 Sep. 2021
Unrecognized function or variable
'formattedDisplayText'.
Error in
CP3_Properties_of_areas_Catanese
(line 105)
fprintf('%s',formattedDisplayText(x));
>> returned this error
Adam Danz
Adam Danz am 29 Sep. 2021
Let me guess, you're using a version of Matlab before R2021a.
Joseph Catanese
Joseph Catanese am 29 Sep. 2021
yes 2020a
Adam Danz
Adam Danz am 30 Sep. 2021
I've updated my answer to include a solution that works prior to R2021a.

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2020b

Gefragt:

am 29 Sep. 2021

Kommentiert:

am 30 Sep. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by