Check values using if condition for each element of two rows in a matrix
9 次查看(过去 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!