Labelling matrix dynamically regardless of its size
Show older comments
Hello,
I want to label an n-by-m matrix dynamically using horzcat. I'm using the following code:
X=[];
for i=1:size(tableau,1)
X=[X strcat('x', num2str(i))];
end
Y=[];
for j=1:size(tableau,2)
Y=[Y strcat('y', num2str(j))];
end
t=horzcat({''; strcat('', X) ;'M'}, ...
vertcat({ strcat('', Y),'N'},...
num2cell(tableau)));
However I'm getting an error "??? Error using ==> vertcat CAT arguments dimensions are not consistent."
The objective is to obtain the following output regardless of the matrix size:
'' 'y1' 'y2' 'y3'
'x1' 5 5 3
'x3' 3 1 3
'x3' 7 6 4
Thanks for your help.
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!