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

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

Jan
Jan 2015년 10월 30일
"With sum extra space so that its not to be seen as part of matrix"? I do not understand the question. Can you post a small example? If so, please append this to the original question, not as comment to a comment. Thanks.
perhaps it should be read: "With some extra space... "
Maybe you could first assign your 20x40 matrix, let it be A = ones(20,40), and another matrix with e.g. B = zeros(30,50), and then you put A into B as B(1:20,1:40) = A; so you have one part with your 20x40 matrix A and some extra space left. Is it that what you're asking for?
for ease of understanding i change the value of matrix from 20x40 to 4X6 with example. thanks
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일

0 개 추천

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.

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

태그

질문:

2015년 10월 30일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by