フィルターのクリア

Combining char and num variables

5 ビュー (過去 30 日間)
Maroulator
Maroulator 2014 年 12 月 9 日
回答済み: Guillaume 2014 年 12 月 9 日
I am looking to see if the following is possible; I seem to remember being able to do it, but the method escapes me right now.
a='No.'; (Character/String Value) b=[1:10]'; (Numeric Value) c=[a b];
For c, I am hoping to get the following in one vertical column vertically. Any ideas?
No. 1 2 3 4 5 6 7 8 9 10

採用された回答

Mohammad Abouali
Mohammad Abouali 2014 年 12 月 9 日
You need to use cell arrays
a='No.'; %(Character/String Value)
b=[1:10]'; %(Numeric Value)
c={a b};
Note the curly braces in defining C.

その他の回答 (1 件)

Guillaume
Guillaume 2014 年 12 月 9 日
As Mohammad says, you can use cell arrays, although to get your values as one vertical column, it would be:
a = 'No.';
b = [1:10]';
c = [{a}; num2cell(b)]
But probably better is to use a table as your 'No.' looks like a header. You'll have to lose the dot though as it's not a valid character for a table header:
a = 'No';
b = [1:10]';
t = table(b, 'VariableNames', {a})
The advantage of a table over a cell array is that you're still manipulating the data as matrices.

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by