Combine Text and number in a matrixs

1 回表示 (過去 30 日間)
aymeric neige
aymeric neige 2020 年 11 月 1 日
回答済み: Ameer Hamza 2020 年 11 月 1 日
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 Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by