How to build a character matrix with matlab?

I would like to build a matrix of characters in Matlab, for example this matrix

M = ['test1', 'test2'; 'Test3', 'test4'];

Is there an easy way to implement it in Matlab?

thanks

+4
source share
1 answer

The command textallows you to create multiple lines at once.

In your example:

M = {'test1','test2';'test3','test4'};

%// adjust x-multiplicator if text becomes very long
[xx,yy] = ndgrid((0:size(M,1)-1)*2+1,1:size(M,2));

figure,
th = text(xx(:),yy(:),M(:));
%// set additional properties, such as centering text horizontally and vertically
set(th,'horizontalAlignment','center','verticalAlignment','middle');

xlim([0 max(xx(:))])
ylim([0,max(yy(:))])
+4
source

Source: https://habr.com/ru/post/1621007/


All Articles