I need to loop through each 2-D array in a 3-d matrix and remove all rows in each 2-3 Array that has 0 in column 2.

4 ビュー (過去 30 日間)
I have a data set that is 360 x 5 x 20 (20 years of annual measurements). Each of the 360 by 5 annual sets has many zeros in column 2 randomly distributed across rows. All rows of all 20 sets containing a zero in any row of column 2 need to be deleted. If I select one set at a time the following works: Testindex = TEST(:,2); idx = Testindex ~=0; TESTOUT = TEST(idx,:);, where TEST is one of the 360 by 5 data sets. I cannot write a code to extend this to loop through each of the 20 sets and perform the removal operation. I have tried for i = 1:20 Testindex2(:,i) = TEST2(:,2,i); idx2(:,i) = Testindex2(:,i) ~=0; TESTOUT2(:,:,i) = TEST2(idx2(:,i),:); end.
How can I do this?
NIckG

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 1 日
編集済み: Azzi Abdelmalek 2013 年 9 月 1 日
Edit
A=randi([0 9],360,5,20); %Example
%-----------------------------------
[n,m,p]=size(A);
B=reshape(A,n,[]);
B(any(B(:,2:m:end)==0,2),:)=[];
out=reshape(B,[],m,p)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by