Matrix of characters

Good morning,
I would like to know how to create a matrix of characters 3x2.

Regards.

Homework?

1 Like
1 Like

Dear mmuetzel and nrjank,
Yes, my question seems banal but it’s extremely important for beginner users like me.
However, thanks to your suggestions, I have finally written my matrix of character.

Now, I have a new problem.
In my programme, I have written the script:

M=ones(2,3);
colwdt = {200 200 200};
t=uitable(panel_output,‘data’,M,‘columnname’,colnam,
‘columnwidth’,colwdt,…
‘ColumnFormat’,[‘string’,repmat({‘bank’},1,11)],…
‘Position’,[8 0 823 235]);

In place of the numeric matrix M=ones(2,3), I would like to use a matrix of characters.
To make an attempt, I have written the following matrix but it doesn’t work.

String1=["a ";"bb ";"cc "]
String2=["dd ";"ee ";"ff "]
String3=["gg ";"hh ";"ll "]
A = [ String1, String2, String3 ]

Could you please clarify what doesn’t work?
Your character matrix A is a (correct) 3x9 character matrix afaict…

The problem is that the function uitable doesn’t show the elements of the matrix on my screen.

%Definition of the character matrix
String1=["a ";"bb ";"cc "]
String2=["dd ";"ee ";"ff "]
String3=["gg ";"hh ";"ll "]
A = [ String1, String2, String3 ]

%Definition of the table
colnam ={‘Temperature’,‘Pressure’,‘Enthalpy’ };
colwdt = {200 200 200};
t=uitable(pannello_output,‘data’,A,‘columnname’,colnam,
‘columnwidth’,colwdt,…
‘ColumnFormat’,[‘string’,repmat({‘bank’},1,11)],…
‘Position’,[8 0 823 235]);

remove the semicolon at the end of the line.

Dear dastew, thank you.

Indeed, nothing changes.

The system shows me the image which I have enclosed to this message.

Instead, I would like to get the following table.

 Temperature        Pressure          Enthalpy
   aa                   bb               cc
   dd                   ee               ff
   gg                   hh               ll

Regards

try running

demo uitable

Does that work?

You’ll likely need to define A as a cell array, e.g. A = {"a", "bb", "cc"; "dd", "ee", "ff"; "gg", "hh", "ll"}.

Turns out this is a typical XY Problem… Please, read that page to make it easier for others to help you.

1 Like

If I use a cell array, it works well.

Yes, next time I will explain my problem in a better way.

Thank you mmuetzel, dastew and nrjank.

1 Like