How do I seperate two columns of data into 12 different variables based on the number from the first column?

1 回表示 (過去 30 日間)
I have a variable with two columns, the first column are numbers that correspond to parameters for an experiment (there are 12 unique parameters total called "speed"), the second column is my raw data. I need to seperate the raw data into 12 different variables based on the numbers from the first column.
One of the parameters is a speed of 4... I pretty much want to tell matlab "If Column one = 4, the number next to 4 will go into a variable called speed4" Is there anyway to do this???

採用された回答

Star Strider
Star Strider 2017 年 5 月 30 日
One approach that appears to work:
Data = [randi(12, 20, 1) randi(99, 20, 2)]; % Create Data
speed = accumarray(Data(:,1), Data(:,2), [], @(x) {cat(2,x)}); % Construct ‘speed’
  4 件のコメント
Marissa Holden
Marissa Holden 2017 年 5 月 31 日
Thank you so so much for your help :)!!

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

その他の回答 (0 件)

カテゴリ

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