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
2012-2-19
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
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!