2

I would like to make a table that contains the numeric values and concatenate those numeric values with the strings.

2 Answers2

2

You cannot combine numbers and strings in same array. You can achieve your goal in multiple ways:

1) Use cell array -

 aq1 = { 'phi ','d[mm]','k[D] ','q[m/day] ','v[m/day] '; 1,2,3,4,5 };
 aq2  = { 'phi ','d[mm]','k[D] ','q[m/day] ','v[m/day] '; [1 2],[2 3; 4 5],3,4,5 };

2) Use struct - In this case you cannot assign brackets and slashes:

aq1 = struct('phi',1,'dmm',2,'kd',3,'qm',4,'v',6);
aq2 = struct('phi',[1 2 3],'dmm',[2 6 ; 7 0],'kd',zeros(7,8),'qm',4,'v',6);

3) Use Map:

aq1 = containers.Map('KeyType','char','ValueType','double');
aq1('phi') = 1
aq1('d[mm]') = 2
aq1('k[D]') = 3

aq2 = containers.Map('KeyType','char','ValueType','any');
aq2('phi') = [1 2 3]
aq2('d[mm]') = [4 5 ; 6 8];
aq2('k[D]') = 3
Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104
  • How can I include a vector for each string instead of a single scalar value? –  Jan 25 '12 at 23:26
1

If you want a nice looking table like the one in your question, you are probably going to have to use HTML. You can look at this as an example of how to format a table for publishing in MATLAB.

If you're data has some structure to it you can put it in a dataset array, and MATLAB will make it look nicer when you disp() it. See the post Printing Variables to HTML Tables in Published Code.

Community
  • 1
  • 1
Rich C
  • 3,164
  • 6
  • 26
  • 37