フィルターのクリア

To remove elements from a matrix and convert into single column

2 ビュー (過去 30 日間)
Sunag R A
Sunag R A 2016 年 12 月 22 日
編集済み: Stephen23 2016 年 12 月 22 日
Hi,
I have one problem with the removal of elements in a matrix, say I have the matrix of 3*3 as
7 8 9;
4 5 6;
1 2 3
I want to extract only 1 2 3 and 7 8 9 nos and that too these should be in a single column as
1
2
3
7
8
9
And also this is in for loop with i = 1:9
How can I do this inside the for loop?
Thanks and Regards,
Sunag R A.

回答 (2 件)

KSSV
KSSV 2016 年 12 月 22 日
Why loop you can straight away extract what you want:
A = [7 8 9; 4 5 6; 1 2 3] ;
% without loop
iwant = [A(end,:) A(1,:)] ;

Sunag R A
Sunag R A 2016 年 12 月 22 日
Thank you very much for the answer. But say I have values like this, for i = 1: 9 in columns like this (1;2;3;4;5;6;7;8;9) I am taking loop because the no's may exceed to 100's later.So.
How to extract the same no's in a single column like deleting 4,5 and 6 nos?
Thanks and Regards,
Sunag R A.
  1 件のコメント
KSSV
KSSV 2016 年 12 月 22 日
You can remove / delete 4,5,6 which falls in second row using
A = [7 8 9; 4 5 6; 1 2 3] ;
A(2,:) = []
To check with many numbers, you have to give conditions, like what numbers you want to delete/ remove.
A = [7 8 9; 4 5 6; 1 2 3] ;
% remove 4,5,6
[m,n] = size(A) ;
B = A ;
for i = 1:m
if any(A(i,:) >=4 & A(i,:)<=6)
B(i,:) = [] ;
end
end
% arrange B in column
iwant = sort(B(:))';

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by