Just wondering if you know how I can get the following matrix:
1.0000 0.8147
2.0000 0.3333
3.0000 0.3322
4.0000 0.1000
1.0000 0.9058
2.0000 0.2222
3.0000 0.3322
4.0000 0.2000
1.0000 0.1270
2.0000 0.1223
3.0000 0.2333
4.0000 0.1000
1.0000 0.9134
2.0000 0.1270
3.0000 1.0000
4.0000 0.1000
1.0000 0.6324
2.0000 0.8899
3.0000 0.0001
4.0000 0.1000
1.0000 0.9870
2.0000 0.5670
3.0000 0.3450
4.0000 0.2000
1.0000 0.8999
2.0000 0.9990
3.0000 0.1235
4.0000 0.4000
1.0000 0.9990
2.0000 0.9990
3.0000 0.9990
4.0000 0.0500
1.0000 0.8147
2.0000 0.3333
3.0000 0.3322
4.0000 0.1000
into a new matrix that takes the left hand column as the indices for the data from the right hand column? ie. I'm trying to get the user to specify the variable they wish to use, so when the user input is say 4, it returns a matrix with all the values in the right hand column that have a 4 next to it in the left hand one.
I had tried using regexp but this only seems to work with characters and not numbers...
Thanks! :)

 採用された回答

Guillaume
Guillaume 2019 年 7 月 22 日

0 投票

selectedvalue = 4;
filteredmatrix = yourmatrix(yourmatrix(:, 1) == selectedvalue, :)

4 件のコメント

Sophie Chumas
Sophie Chumas 2019 年 7 月 22 日
Hi!
Thank you!
This works as it returns the 4, but doesnt return the associated values...Am I typing it out wrong?
u_s_v = input('Select the variable you wish to use by typing the number of its position in the list of variables.');
chosen_variable = data_matrix(data_matrix(:, 1) == u_s_v);
disp(chosen_variable);
Torsten
Torsten 2019 年 7 月 22 日
You forgot
, :
behind u_s_v.
Sophie Chumas
Sophie Chumas 2019 年 7 月 22 日
Done it!
u_s_v = input('Select the variable you wish to use by typing the number of its position in the list of variables.');
chosen_variable = data_matrix((data_matrix(:, 1) == u_s_v), 2);
disp(chosen_variable);
Thank you!!!!! :D
Sophie Chumas
Sophie Chumas 2019 年 7 月 22 日
I thought the , :) was a smiley face! Sorry!!! Thanks for pointing it out. Should've figured people don't use smiley faces during coding...:')

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by