フィルターのクリア

How can I return cell array values using an index matrix.

1 回表示 (過去 30 日間)
Aaron Jean-Baptiste
Aaron Jean-Baptiste 2017 年 10 月 1 日
コメント済み: Walter Roberson 2017 年 10 月 2 日
Hi there,
I have the following variables:
variableNames = {'Aaron', 'Brett', 'Charlie', 'Katie', 'Jess'}
index_matrix = [1,3,4,5,2; 2,1,4,5,3; 3,2,1,5,4]
and I want to return the variableName corresponding to that index in a new cell array or timetable:
index_name = {'Aaron','Charlie','Katie','Jess','Brett';
'Brett','Aaron','Katie','Jess','Charlie';
'Charlie','Brett','Aaron','Jess','Katie'}
My index_matrix is actually in a timetable, but I suppose once I have a solution for this I can adjust it.
Many thanks,
Aaron

採用された回答

Walter Roberson
Walter Roberson 2017 年 10 月 1 日
index_name = variableNames(index_matrix);
  3 件のコメント
Aaron Jean-Baptiste
Aaron Jean-Baptiste 2017 年 10 月 2 日
That was embarrassingly easy. I suppose a follow-up is that I want to store this cell array as a time-series. I.e. I want to see on what date did 'Aaron' come first. How can I store the data in this ordered format?
Walter Roberson
Walter Roberson 2017 年 10 月 2 日
timeseries() does not appear to be usable for cell array of strings.
You could convert to categorical... which would effectively look like your index matrix internally.
You could create a timetable() if you have a sufficiently new MATLAB.

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

その他の回答 (0 件)

カテゴリ

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