how to take a matrix of certain values taken from the matrix
2 ビュー (過去 30 日間)
古いコメントを表示
Muhammad Dzul Akbar
2018 年 8 月 23 日
コメント済み: Muhammad Dzul Akbar
2018 年 8 月 24 日
hello guys,
I am a beginner in using matlab, and I have a case which I can't solve it, can anyone help?
I have a 7 x 2 input matrix, as I demonstrated below
A = [1 100
2 110
3 120
4 130
5 140
6 150
7 160]
and then i have a value of 125. from that value i want i get a new matrix that is
B = [3 120
4 130]
Could someone help me please?
dzulakbar
0 件のコメント
採用された回答
Walter Roberson
2018 年 8 月 23 日
q = 125;
idx = interp1(A(:,2), (1:size(A,1)).', q);
B = A(floor(idx):ceil(idx), :);
This relies upon the entries in the second column being monotonic (all increasing or all decreasing.)
3 件のコメント
madhan ravi
2018 年 8 月 23 日
If the code is working you can thank the person by accepting their answer.
その他の回答 (1 件)
Andrei Bobrov
2018 年 8 月 23 日
編集済み: Andrei Bobrov
2018 年 8 月 23 日
q = 125;
[~,inx] = mink(abs(A(:,2) - q),2);
B = A(inx,:);
or for old MATLAB
q = 125;
[~,inx] = sort(abs(A(:,2) - 125));
B = A(inx(1:2),:);
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!