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

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 14 Apr. 2011

0 Stimmen

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

2 Kommentare

Daniel
Daniel am 14 Apr. 2011
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 am 14 Apr. 2011
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by