Hello! I cleaned my signal from emissions, it is in the form of a matrix, but there I used i-1, in consequence of which, instead of 1100, I now have 1099 values, how can I add the last value?\
for i = 1:length(d)-1 % Error 1100 1099
if g(i)-50>= g(i+1);
f(i)=g(i);
end
end

6 comentarios

Stephen23
Stephen23 el 5 de Jul. de 2019
Editada: Stephen23 el 5 de Jul. de 2019
Your question is not very clear, but possibly you should preallocate the output array:
Lev Mihailov
Lev Mihailov el 5 de Jul. de 2019
Sorry, I do not quite understand, I need a condition
if c (i) + 10 > size (Matrix, 1);
before that, I simply used 'r' which was 1100, now I’m using 'c' which is 1099, and the matrix itself is 1100
Error Index exceeds matrix dimensions.
How do c and Matrix relate to f and g?
DId you try Stephen's suggestion of putting
f = zeros(size(g));
before your original for loop?
Jan
Jan el 5 de Jul. de 2019
Editada: Jan el 8 de Jul. de 2019
@Lev: I do not see the relation between
if g(i)-50>= g(i+1);
and
if c (i) + 10 > size (Matrix, 1)
Which problem do you want to solve? What about:
f = g(diff(g) < -50)
instead of the loop?
Lev Mihailov
Lev Mihailov el 5 de Jul. de 2019
Cycle loop has nowhere
f = zeros(size(g));
% why do i need to convert to zeros?
The problem removed the outliers from the signal was 1099 values ​​(these are the positions of the maxima), but in the matrix there are 1100 values
Jan
Jan el 8 de Jul. de 2019
@Lev: |zeros()< does not convert anything to zeros. Please read the documentation:
doc zeros
to find out, that this is a pre-allocation of the output. Letting an array grow iteratively is extremely inefficient. Matlab has to allocation a new array in each iteration. So:
r = [];
for k = 1:1e6
r(k) = rand;
end
needs 8*1e6 bytes finally, but intermediately 8*sum(1:1e6) bytes are allocated: 4 TeraByte!
I do not understand the meaning of your comment. If you detect outliers by subtracting pairs elements, of course there is one element less in the output.

Iniciar sesión para comentar.

Respuestas (2)

dpb
dpb el 5 de Jul. de 2019

0 votos

Adding to Stephen's answer Matlab syntax, the crystal ball says
for i = 1:length(d)-1 % Error 1100 1099
if g(i)-50>= g(i+1);
f(i)=g(i);
end
end
becomes
f=zeros(size(g));
ix=diff(g)<-50;
f(ix)=g(ix);
Lev Mihailov
Lev Mihailov el 5 de Jul. de 2019

0 votos

Still nothing happened, gives an error
Index exceeds matrix dimensions.

5 comentarios

Lev Mihailov
Lev Mihailov el 5 de Jul. de 2019
I have values ​​in an array, can't I just add a value like 1100?
dpb
dpb el 5 de Jul. de 2019
  1. We can't see your terminal -- an error out of context with code that produced it is meaningless...paste the entire red text and the preceding code line that produced the error.
  2. You can always augment an array, yes, but you have to do so by a form that is allowable catenation, not by reference outside an existing array bounding.
The code I gave cannot produce an indexing array bounds error...and will have resulting array f of same size as g
Lev Mihailov
Lev Mihailov el 5 de Jul. de 2019
Editada: dpb el 5 de Jul. de 2019
[d,g]=max(Matrix);
for chek = 1:length(d)-1
if g(chek )-50>= g(chek +1);
c(chek )=10;
else g(chek )+50 <= g(chek +1);
c(chek)=g(chek );
end
end
for i = 1:length(d)
if c(i)+10>size(Matrix,1);
aan=Matrix(c(i):end,i) ;
aa=Matrix((c(i)-10:c(i)),i) ;
У{i}=aa(aa ~= 0);
Х{i}=aan(aan ~= 0);
end
here is the full code
Index exceeds matrix dimensions.
Error in Senteb2019 (line 260)
if c(i)+10>size(Matrix,1);
dpb
dpb el 5 de Jul. de 2019
c can only have length(d)-1 elements in it...as has been said multiple times before, preallocate it to the size wanted or compensate that there will always be one less array element since you're dealing with diff() functionality that produces one less element by its very nature.
dpb
dpb el 5 de Jul. de 2019
Editada: dpb el 5 de Jul. de 2019
In
for chek = 1:length(d)-1
if g(chek )-50>= g(chek +1);
c(chek )=10;
else g(chek )+50 <= g(chek +1);
c(chek)=g(chek );
end
end
the else clause should be elseif it appears.
What is the value for c if abs(diff(g))<50?
Again, use Matlab array syntax; the above loop construct (presuming the "elseif" and zero for then missing "else" clause)
c=zeros(size(g)); % preallocate to same size as g array
ix=diff(g)<-50;
c(ix)=10;
ix=diff(g)>=50;
c(ix)=g(ix);
You need to define what happens in the other cases not satisfied...if they're to remain unchanged, then use
c=g;
for initialization instead of zeros

Iniciar sesión para comentar.

Categorías

Productos

Preguntada:

el 5 de Jul. de 2019

Comentada:

Jan
el 8 de Jul. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by