필터 지우기
필터 지우기

Select values from 20 x 15 matrix based on a row vector 1 x 15

조회 수: 2 (최근 30일)
I'm trying to extract values from matrix A (20 x 15) which are less than values in matrix B (1 x 15). Matrix B has 15 columns with threshold values determined from newspaper analysis. How to extract values from each column of matrix A which are less than values from corresponding columns from matrix B?
I have tried C = A < B; but I'm not able to fix matrix dimension error.
  댓글 수: 1
Steven Lord
Steven Lord 2019년 11월 7일
Which release of MATLAB are you using? It may be relevant particularly if you're using a release prior to release R2016b, when we introduced implicit expansion.

댓글을 달려면 로그인하십시오.

채택된 답변

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 11월 7일
solution:
A(A>=B)=nan;
disp(A)
c=num2cell(A,1);
for k=1:size(c,2)
c{k}(isnan(c{k}))=[];
disp(['Column ' num2str(k)])
disp(c{k})
end
  댓글 수: 2
Parthu P
Parthu P 2019년 11월 7일
Thanks for reply.
Actually I have tried the simillar loop before but I'm not able to fix dimension error related to B.
For example, in "C = A < B"
If I make "C = A < B (:,1)" or "C = A < B (:,15)". It read B value in either 1st or 15th column and apply it to all the columns. How do i put right dimensions for "B (. . . . . )", so that it reads correct B value for corresponding individual columns of matrix A?
JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 11월 7일
This works well for the dimensions you indicated, could you save your workspace and attach it? look at an example:
A=rand(20,15);
B=rand(1,15);
A(A>B)=nan;
disp(A)
c=num2cell(A,1);
for k=1:size(c,2)
c{k}(isnan(c{k}))=[];
disp(['Column ' num2str(k)])
disp(c{k})
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

kondepati sudhir kumar
kondepati sudhir kumar 2019년 11월 7일
if use the C = A <B; you wil get the logic matrix. If you have dimensional error then it is better give the c = zeros (size (a));
i hope it works.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by