how do I select every single element of matrix except middle
2 ビュー (過去 30 日間)
古いコメントを表示
Say for example I have a 3 by 3 matrix
[1,2,3;4,5,6;7,8,9]
How do I select every element of the matrix except for the middle element?
2 件のコメント
David Young
2015 年 1 月 16 日
What do you mean by "select"? In other words, what operation are you going to carry out on the non-central elements?
回答 (1 件)
Niels
2015 年 1 月 16 日
編集済み: Niels
2015 年 1 月 16 日
If I understand you correctly, you could do something like this:
A(A~=A(ceil(numel(A)/2)))
or
setdiff(A,A(ceil(numel(A)/2)))
Assuming you always have an odd number of elements these approaches should work.
Considering your edit, you could do it like this:
B = A([1:ceil(numel(A)/2)-1, ceil(numel(A)/2)+1:end]) * whatever;
Or, keeping it within A;
A([1:ceil(numel(A)/2)-1, ceil(numel(A)/2)+1:end]) = ...
A([1:ceil(numel(A)/2)-1, ceil(numel(A)/2)+1:end]) * whatever;
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!