Info
此问题已关闭。 请重新打开它进行编辑或回答。
Сomparison of columns in the matrix
1 次查看(过去 30 天)
显示 更早的评论
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
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).
回答(1 个)
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 个评论
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!