Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
AMIT BHASKAR
AMIT BHASKAR 2015년 10월 30일
마감: MATLAB Answer Bot 2021년 8월 20일
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
AMIT BHASKAR
AMIT BHASKAR 2015년 10월 30일
for ease of understanding i change the value of matrix from 20x40 to 4X6 with example. thanks
Ilham Hardy
Ilham Hardy 2015년 10월 30일
Firstly, that's not how the flag works.
Secondly, WHY do you want to do that?

답변 (2개)

Ced
Ced 2015년 10월 30일
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 2015년 11월 7일
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.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by