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