0
votes

I have a small function that finds the peaks in a matrix and then replacing it by 0. The end output is related to the columns. I'm having hard time fixing the syntax to make it work the same way but for the rows as well. Any ideas ? Here's the code :

HVAzimuthFreqAbs = abs(HVAzimuthFreq);
M = HVAzimuthFreqAbs;
for k1 = 1:size(M,1)
[pks,loc] = findpeaks(M(k1,:),'Threshold',150);
P{k1} = [pks; loc];
end
HVAzimuthFreq(:,loc) = 0;

The main key as I understand is to switch between the order that the size refers to, but I have no luck in doing that. For example -

for k1 = 1:size(1,M)
[pks,loc] = findpeaks(M(:,K1),'Threshold',ThresholdUpper);
P{k1} = [pks; loc];
end

is giving me an 'Dimension argument must be a positive integer scalar within indexing range' error.

Any ideas ? thanks

1
Swap the dimensions around? What exactly is the problem?Mad Physicist
I'm a novice in Matlab, How do I swap the dimensions ? everything that I try results in an errorGeoRay
Show your attempts. Edit them into the question. Do not do it in the comments. Explain what goes wrong with each, in detail. Right now this looks like a request for free code, which is off topic here.Mad Physicist
does findpeaks(M(:,K1).','Threshold',ThresholdUpper); work for you?Ander Biguri

1 Answers

0
votes

Your error is at the for line, size(1,M) makes no sense. Use size(M,2) to get the number of columns.

You are indexing the columns as M(:,K1), this is correct.