Info

This question is closed. Reopen it to edit or answer.

Сomparison of columns in the matrix

6 views (last 30 days)
Lev Mihailov
Lev Mihailov on 5 Jul 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello! I need to compare the columns in the matrix.I found maxima in my matrix and now I need to check for correctness.
Maximum values ​​of my columns 20 21 22 20 78 22 23 25 55 108 22 33 22. but some of them greatly exceed 70. I need to create a 'for' loop to check 5 columns.
By the type of 'i' the first column +5 columns is not more than 50 then it is true, if it is larger then false
for i = 1:length(d)
if g(i)>=g(i)+50;
f(i)=g(i);
elseif g(i)<g(i)+50
f(i)=0 ;
end
end
Error Index exceeds matrix dimensions.
when i go to i + 5
  5 Comments
Guillaume
Guillaume on 5 Jul 2019
"I work with a large matrix. Therefore, the cycle is desirable"
Using a loop won't gain you anything. It will just result in slower and more complicated code.
It's still unknown what you are trying to achieve. "If it's true", if what is true? As both Chimnay and I wrote, the condition you wrote is nonsensical (it's always false).
Lev Mihailov
Lev Mihailov on 5 Jul 2019
The cycle is convenient for me. True to my terms.
first position is correct r (1) = 200, but all the others need to be checked, r (1) is more or less r (2) +50, r (2) = 240, the test passes, then r (2) with r (3), etc. r(3)=700
for i = 1:length(d)-1
if g(i)>= g(i+1);
f(i)=0;
else g(i)+50 <= g(i+1);
f(i)=g(i);
elseif g(i)-50 <= g(i+1);
f(i)=g(i);
end
end
In general, my task is just to get rid of the emissions of my signal

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 5 Jul 2019
Edited: KALYAN ACHARJYA on 5 Jul 2019
No need loop and if else
col=[20 21 22 20 78 22 23 25 55 108 22 33 22];
idx=find(condition...); %Condition like col<50 or as per your requirements
col(idx)=0
  2 Comments
Lev Mihailov
Lev Mihailov on 5 Jul 2019
col=[g];
idx=find(g<50); %Condition like col<50 or as per your requirements
col(idx)=0;
it just doesn't suit me
KALYAN ACHARJYA
KALYAN ACHARJYA on 5 Jul 2019
Edited: KALYAN ACHARJYA on 5 Jul 2019
Are you looking for this one?
g=[20 21 22 20 78 22 23 25 55 108 22 33 22];
idx=find(g<50); %Condition like col<50 or as per your requirements
g(idx)=0;
disp(g)
Have you read the comment by Guillaume.

This question is closed.

Products

Community Treasure Hunt

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

Start Hunting!