Working with character matrices

Hi everyone,
I am trying to put together a matrix that incorporates both numbers and letters. This matrix needs to be able to have basic row and column switching operations done on it.
This is the matrix that I would like to use: [1,a,b,c; d,1,e,f; r,s,1,t;u,v,w,1] How would I input this into Matlab?
Thanks in advance!

답변 (2개)

Image Analyst
Image Analyst 2012년 2월 19일

0 개 추천

As long as you have just single characters, you can simply put single quotes around each character:
myString = ['1','a','b','c'; 'd','1','e','f'; 'r','s','1','t';'u','v','w','1'];
If there will be different lengths, then you will need to use a cell array.
Walter Roberson
Walter Roberson 2012년 2월 19일

0 개 추천

You cannot mix numbers and letters in any kind of numeric MATLAB array. The only kind of array that can handle it is a cell array.

댓글 수: 2

Dmytri
Dmytri 2012년 2월 19일
In a cell array can you multiply it by an identity matrix or are operations on cells not allowed?
Jan
Jan 2012년 2월 19일
You cannot apply mathematical operation on cells. This would not make sense at all: While I can imagine what 1*1 is, 1*'a' is valid in Matlab, but has a limited sense only.
Perhaps you want to work with symbolical values, where 'a' represents a variable?

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2012년 2월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by