フィルターのクリア

How to insert a new row on top of the matrix with a different label and insert a new column at the end with the same label

11 ビュー (過去 30 日間)
Hello everyone,
I need to create a new row on top of the 132x500 matrix that labeled with C1:C500 and then, a new column at the end that store the same value which is 'Type A' for the whole 132 data. I did use sym function however it gives a lot of burden to my Matlab until it stops multiple time. Thanks in advanced.
sample = rand(132,500);
labelRow = sym('c', [1 500]);
ResultLabelRow= [labelRow;sample];

採用された回答

Walter Roberson
Walter Roberson 2017 年 8 月 10 日
Numeric arrays and sym() do not support labels.
The labels you want happen to be acceptable as variable names for a table() object, and they happen to be sequentially numbered in a way that happens to work out, so you could do
C = sample; %magic variable name to make the table work columns work out
ResultRowLabel = array2table(C);
If C does not happen to be available as a variable name to store the data in temporarily, then for R2016b or later,
labelRow = cellstr( string('C') + (1:size(sample,2)) );
ResultRowLabel = array2table(sample, 'VariableNames', labelRow);
For earlier versions,
labelRow = cellstr( num2str((1:size(sample,2)).', 'C%d') );
If you do not wish to use a table, then you will need to go into cell arrays,
labelRow = cellstr( string('C') + (1:size(sample,2)) ) .';
ResultRowLabel = [labelRow; num2cell(sample)];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by