フィルターのクリア

Merge row and column headers into column header or Get Index Names

1 回表示 (過去 30 日間)
Kevin Teh
Kevin Teh 2018 年 12 月 14 日
編集済み: Jan 2018 年 12 月 14 日
Hi
This might be an easy qn sorry. So for simple example i have two headers. One 4x1 row header and one 1x4 column header as such
monkey rabbit tiger snail
monkey
rabbit
tiger
snail
What i want to achieve is 16 combination with the word vs in the middle. This will be the final column header. So output will be:
monkey vs monkey monkey vs rabbit monkey vs tiger monkey vs snail rabbit vs monkey ............ snail vs tiger snail vs snail
Is there a way to quickly get the names of an index ie monkey vs monkey =1,1 snail vs snail 16 x 16. Thank you for any help.
col = {'monkey', 'rabbit', 'tiger', 'snail'};
row = {'monkey', 'rabbit', 'tiger', 'snail'}';
Kevin
  1 件のコメント
Jan
Jan 2018 年 12 月 14 日
It would be useful if you reveal, what the inputs are. "One 4x1 row header" is less clear than posting, if it is e.g.:
col = {'monkey', 'rabbit', 'tiger', 'snail'}

サインインしてコメントする。

採用された回答

Jan
Jan 2018 年 12 月 14 日
編集済み: Jan 2018 年 12 月 14 日
col = {'monkey', 'rabbit', 'tiger', 'snail'};
row = {'monkey', 'rabbit', 'tiger', 'snail'}; % can differ from col
Result = cell(numel(col), numel(row));
for c = 1:numel(col)
for r = 1:numel(r)
Result{c, r} = [col{c}, ' vs ', row{r}];
end
end
Or without a loop:
nCol = numel(col);
nRow = numel(row);
Result = strcat(repmat(col(:), 1, nRow), {' vs '}, repmat(row, nCol, 1));

その他の回答 (0 件)

カテゴリ

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