Letters in Matrix

I am constructing a matrix consisting of letters, however at the moment it is not working. I was wondering if you could help. My present code is;
function LettersMatrix
M=16;
C = zeros(M);
for i=1:2:3
C(i,2)=-B/H;
end
for i=1:2:3
C(i+4,2)=B/H;
end
disp(transpose(C));
I think the command char, or cell is needed though i am unsure. Can anyone help;
Kind Regards
Dan

 採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 4 月 14 日

0 投票

You want this solution?
C = cell(16);
k = 1:3;
C(k,2) = {'-B/H'};
C(k+4,2) = {'B/H'};
C'

2 件のコメント

Daniel
Daniel 2011 年 4 月 14 日
Thankyou, that works! however do you know how to change the matrix from displaying the letters as 'B/H' now? Preferably the matrix would just show the letters as B/H without the ' ' either side.
Walter Roberson
Walter Roberson 2011 年 4 月 14 日
char() can convert a cell array to a character array, but probably only a cell vector at a time. The task would be easier if the cells were exactly the same size.
If you want to convert to an array of character, you are going to need to choose how much padding there is between entries, and the entries will lose their identity as individual entries, becoming instead just parts of a big block of characters. The only way to make it possible for a cell array of character strings to display without the ' ' around the entries is to write a new display() method for data type cell.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by