Check values using if condition for each element of two rows in a matrix
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I need to check values of each element of rows (2,:) and (1,:), (3,:) and (2.:) and so on upto 8 rows. The matix size is 8 x 40 and the values have zeros and decimal values (10.5, 100.2, 154.2 etc)
How can I implement to check for set of conditions for pair of rows at a time changing row numbers?
For example, suppose my matrix is AA(8x40) IF(AA(2,1)>0.1,IF(AA(2,1)=0,IF(AA(2,1)=0,IF(AA(1:1)=0,"1","0"))))
Above is the MS Excel function.
How can I implement this in MATLAB?
Can anyone help,
Thanks.
댓글 수: 2
Chris C
2014년 3월 17일
I'm sorry. I really don't understand your questions. You want to check the rows of your matrix right? For what? That each element is the same? That one is larger than another.... there are nearly unlimited permutations of "checking" your matrix. If you could maybe try and explain the challenge a little more clearly, then I'd be happy to help.
답변 (1개)
Mischa Kim
2014년 3월 17일
편집: Mischa Kim
2014년 3월 17일
Damith, this is the basic structure:
data = rand(8,40);
for ii = 1:length(data(:,1))-1 % loop through all rows
if sum(data(ii,:)) > sum(data(ii+1,:)) % iith and (ii+1)st row
...
elseif *CONDITION*
...
else
...
end
end
댓글 수: 6
Joseph Cheng
2014년 3월 18일
편집: Joseph Cheng
2014년 3월 18일
I see how you are writing it now, not the best way to write it out. as a suggestion next time you are trying to reference 2 rows in a matlab setting would be AA(1:2,:)>0.1 instead of AA(2,1)>0.1. AA(1:2,:) saying rowas 1 to 2 for all columns. I thought you AA(2,1) was referencing row 2 column 1 of AA. Such that your first conditioning only was looking at the previous row in the most nested if statement of IF(AA(1:1). I'll think about it over night and see if i can get something by the morning.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!