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 Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2011년 4월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by