add a string column to integer matrix

3 ビュー (過去 30 日間)
yaniv friedman
yaniv friedman 2016 年 6 月 5 日
コメント済み: yaniv friedman 2016 年 6 月 5 日
I have a Data matrix of 5 columns and many rows, all integers.
I wish to add a 6th column of strings, using a condition on the value of one of the columns (Lets say the 3rd):
If Data(:,3) == 1 , add 6th column string value 'Upper', and else- add it as 'Lower'.
the type of the finished array may be cell or table, because I will export it as a txt file.
Thanks!

回答 (1 件)

the cyclist
the cyclist 2016 年 6 月 5 日
Here's one way:
data = round(rand(7,5));
[m,n] = size(data);
textCol = cell(m,1);
upperIndex = data(:,3)==1;
textCol(upperIndex) = {'Upper'};
textCol(not(upperIndex)) = {'Lower'};
outputCell = [num2cell(data),textCol]
  1 件のコメント
yaniv friedman
yaniv friedman 2016 年 6 月 5 日
great! thanks

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by