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

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 14 de Abr. de 2011

0 votos

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

2 comentarios

Daniel
Daniel el 14 de Abr. de 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 el 14 de Abr. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Abr. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by