Info

此问题已关闭。 请重新打开它进行编辑或回答。

Сomparison of columns in the matrix

1 次查看(过去 30 天)
Lev Mihailov
Lev Mihailov 2019-7-5
关闭: MATLAB Answer Bot 2021-8-20
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 个评论
Guillaume
Guillaume 2019-7-5
"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 2019-7-5
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

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-7-5
编辑:KALYAN ACHARJYA 2019-7-5
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 个评论
Lev Mihailov
Lev Mihailov 2019-7-5
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 2019-7-5
编辑:KALYAN ACHARJYA 2019-7-5
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.

此问题已关闭。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by