Info
This question is closed. Reopen it to edit or answer.
Сomparison of columns in the matrix
6 views (last 30 days)
Show older comments
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
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).
Answers (1)
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
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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!