Matrix consist of letters

조회 수: 1 (최근 30일)
Cillian
Cillian 2012년 5월 10일
Hello.
I really want to know if it is possible to fill a matrix with x,y and z.
Here is my attempt so far:
>> X=zeros(3,10)
X =
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
>> X(1,:)=[1 :10]
X =
1 2 3 4 5 6 7 8 9 10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
I have succeed to fill the first row with number, from 1 to 10. But, what if I want to fill the first rows with only letters, just 'x' in the first row, is that possible?
I would be very happy if someone can help me and answer on my question.
Best Regards
Cillian
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 5월 10일
What you have is a matrix of doubles. Letters would be chars and you cannot mix them together unless you use cell arrays.
Before showing how would you go about with a cell array, what do you need this type of "matrix" for?

댓글을 달려면 로그인하십시오.

채택된 답변

Daniel Shub
Daniel Shub 2012년 5월 10일
Do you want something like this
X = [repmat('x', 1, 10); repmat('y', 1, 10); repmat('z', 1, 10)]
Or maybe this makes more sense
X = zeros(3,10);
X(2, :) = 1;
X(3, :) = 2;
X = char(X+120)
basically the characters "x", "y", and "z" have values of 120, 121, and 122.
  댓글 수: 1
Cillian
Cillian 2012년 5월 10일
Thanks, Daniel. That was exactly what I looking for.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by