Combine Text and number in a matrixs

1 次查看(过去 30 天)
Hi, I have a simple question about a script that i wrote.
My problem is this:
I have 4 matrice : A B C D and each of them has (10x1 cells).
I want to combine text and number in a matrixe like:
'A' 'B' 'C' 'D'
2 3 4 5
4 5 6 7
... ... ... ...
so i wrote this one :
Total = [{'LLO'},LLO;{'LLF'},LLF;{'RLO'},RLO;{'RLF'},RLF]';
but when i run it i have :
'A' 'B' 'C' 'D'
(2,4,...) (3,5,...) (4,6,...) (5,7,...)
As i want to export my matrix to excel, i can't.
Any Ideas ?

回答(2 个)

Ameer Hamza
Ameer Hamza 2020-11-1
Try something like this
LLO = randi([1 10], 1, 10);
LLF = randi([1 10], 1, 10);
RLO = randi([1 10], 1, 10);
RLF = randi([1 10], 1, 10);
result = [{'LLO', 'LLF', 'RLO', 'RLF'}; num2cell([LLO(:), LLF(:), RLO(:), RLF(:)])]
Result
>> result
result =
11×4 cell array
{'LLO'} {'LLF'} {'RLO'} {'RLF'}
{[ 1]} {[ 1]} {[ 4]} {[ 10]}
{[ 9]} {[ 4]} {[ 10]} {[ 10]}
{[ 9]} {[ 7]} {[ 3]} {[ 6]}
{[ 6]} {[ 9]} {[ 6]} {[ 2]}
{[ 8]} {[ 7]} {[ 8]} {[ 4]}
{[ 6]} {[ 7]} {[ 3]} {[ 3]}
{[ 6]} {[ 7]} {[ 9]} {[ 3]}
{[ 2]} {[ 8]} {[ 6]} {[ 3]}
{[ 6]} {[ 7]} {[ 10]} {[ 1]}
{[ 1]} {[ 6]} {[ 4]} {[ 9]}

madhan ravi
madhan ravi 2020-11-1
Wanted = {'A' 'B' 'C' 'D'
2 3 4 5
4 5 6 7} % as cell array
Wanted = 3x4 cell array
{'A'} {'B'} {'C'} {'D'} {[2]} {[3]} {[4]} {[5]} {[4]} {[5]} {[6]} {[7]}
  1 个评论
aymeric neige
aymeric neige 2020-11-1
ok it work but instead of 2,3,4,5 (example) i have matrix : RLL LLL RUL LUF.
Each of it has 10 cells and i don't want to write them one-by-one. So that commande
wanted = {'A' 'B' 'C' 'D'
RLL LLL RUL LUF}
doesn't work and i have the same issue.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by