How to create a signal matrix
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tommaso Fornaciari
el 5 de Dic. de 2016
Comentada: Tommaso Fornaciari
el 7 de Dic. de 2016
Hello, I am trying to replicate a matrix (signals2) that gives me signals of 1,0 or 1 depending on the value of each single observation in another matrix (rankfull2)-the two have the same size. I would like matrix "signals2" to show 1 when the value is above 319, -1 when is below 60 and 0 otherwise.
for iii=1:size(rankfull2,1)
for jjj= 1:size(rankfull2(1,:),2)
if rankfull2(iii,jjj) < 60
signals2(iii,jjj)= -1;
elseif rankfull2(1,jjj) > 319
signals2(iii,jjj)= 1;
else signals2(iii,jjj)= 0;
end
end
end
The output that I get seems to understand the rule of lower than 60 but not the one above 319, returning a 0 instead of a 1 (each row contains at leat 50 values above 319)
Could you someone advise if there is something wrong with my loop or if I am unaware of certain matlab rules?
Thank you in advance.
0 comentarios
Respuesta aceptada
David Barry
el 5 de Dic. de 2016
Editada: David Barry
el 5 de Dic. de 2016
It looks like the issue might be because you are only looking in the first row of rankfull2 with your >319 line of code. Anyway, there is a much cleaner way of doing this without the need for loops. You should take a look at logical indexing.
signals2 = zeros(size(rankfull2));
signals2(rankfull2 < 60) = -1;
signals2(rankfull2 > 319) = 1;
3 comentarios
David Barry
el 6 de Dic. de 2016
Editada: David Barry
el 6 de Dic. de 2016
I don't completely follow what you need to do but it sounds like you might need to make use of the insan function along with the logical indexing examples I provided. You could also use the sum function to count the number of NaN in each column if that is what you need.
Take a look at what this example produces:
a = [1, 2, NaN, 4; NaN, 6, 7, 8; NaN, 10, 11, 12];
idx = isnan(a)
sum(idx)
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!