MATLAB: Creating a three column table from matrix

matrix manipulation

If I have a matrix, how can I make a table with three columns that are row number, column number, and then the value for that row-column? And then, add a 4th column with the row-column number? example in picture

Best Answer

Hi,
because you want a string in your 4th column, you need a cell array. here's my q&d solution:
A=rand(3,3);
new = cell(numel(A),4);
kk=1;
for ii = 1:size(A,1);
for jj = 1:size(A,2);
new{kk,1}=ii;
new{kk,2}=jj;
new{kk,3}=A(ii,jj);
new{kk,4}=[num2str(ii) '-' num2str(jj)];
kk=kk+1;
end;
end
Regards
Julian
Related Question