Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

hello everyone, i have a problem in labeling the matrix.

1 visualizzazione (ultimi 30 giorni)
AMIT BHASKAR
AMIT BHASKAR il 30 Ott 2015
Chiuso: MATLAB Answer Bot il 20 Ago 2021
let's suppose i have 4x6 matrix, i want to assign each row as [1 2 3 4] similarly column [1 2 3 4 5 6] with some extra space with current matrix so that its not be seen as the part of matrix and at the end,matrix dimension should not change(i.e. 4x6). how can i do? can u help please? for example
d= 11 12 13 14 15 16
17 18 19 21 22 24
27 28 25 2 44 45
23 23 23 3 3 3
d is a matrix, i want to represent this as
d=
1 2 3 4 5 6
1 11 12 13 14 15 16
2 17 18 19 21 22 24
3 27 28 25 2 44 45
4 23 23 3 3 3 3
but the important thing is, i don't want 1:6 Z& 1:4 as a part of matrix,i.e. matrix dimension should not change i.e. 4x6,only additional part is, matrix d has labeled now.
  5 Commenti
AMIT BHASKAR
AMIT BHASKAR il 30 Ott 2015
for ease of understanding i change the value of matrix from 20x40 to 4X6 with example. thanks
Ilham Hardy
Ilham Hardy il 30 Ott 2015
Firstly, that's not how the flag works.
Secondly, WHY do you want to do that?

Risposte (2)

Ced
Ced il 30 Ott 2015
This is ugly, but should do the trick. Not sure why you want this though...
function print_my_mat(A)
nrows = size(A,1);
ncols = size(A,2);
my_cell = cell(nrows+1,ncols+1);
my_cell(1,2:end) = num2cell(1:ncols); % number your columns
my_cell(2:end,1) = num2cell(1:nrows); % number your rows
my_cell(2:end,2:end) = num2cell(A); % write your matrix inside cell
for i = 1:nrows
% format your numbers as desired and save as string
temp = cellfun(@(x)num2str(x,'%i'),my_cell(i,:),'UniformOutput',0);
% print row
cellfun(@(x)fprintf('%4s',x),temp,'UniformOutput',0);
% next line
fprintf('\n')
end
end

Walter Roberson
Walter Roberson il 7 Nov 2015
You would need to define a new data class of labeled matrix. You could possibly subclass from double precision so that you would not have to re-code all of the numeric operations. You would have to code a new display() method for the class.
But it is easier by far to just write a small bit of code that displays the matrix in that form when you ask it to.

Questa domanda è chiusa.

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by