How to delete elements on specific indices?
385 ビュー (過去 30 日間)
古いコメントを表示
I was able to get the correct output which I wanted with the code written in Python.
However, I have no idea how to write it in MATLAB after the follwoing scripts.
MATLAB code
outliers = [1,3,7]; %outliers are indices numbers to delete
elm = [1, 2, 3, 4, 5, 6, 7, 8, 9];
%preferred output
[1, 3, 5, 6, 7, 9]
Python code
outliers = [1,3,7]
elm = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(len(outliers)-1, -1, -1):
elm.pop(outliers[i])
print(elm)
0 件のコメント
採用された回答
Debasish Samal
2019 年 6 月 7 日
You can achieve this on matlab by using the following code.
outliers = [1,3,7];
elm = [1, 2, 3, 4, 5, 6, 7, 8, 9];
elm(outliers+1) = []; %indexing using outliers and setting them to NULL
Notice that in MATLAB indexing starts from 1 instead of 0. So you have to add 1 to the index matrix (outliers).
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!