How to determine sign change in a matrix for each coulmn separatly
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hazem Abdelsalam
el 30 de Jul. de 2015
Comentada: Star Strider
el 31 de Jul. de 2015
Hello, I have three plots represented by bo matrix I want to calculate the points at which the sign changed for each curve separately. I wrote the following code and I got ZZ but ZZ is on row and I can't differentiate between sign change in each single curve. thanks in advance Hazem
clear all;close all;
b0=[1,2,3,-2,-3,7;3,4,7,-5,-3,4,;-3,-4,6,7,-1,-2];b0=b0';
ee=[1 2 3 4 5 6];plot(ee,b0)
ZZ=[];
for ib=1:size(b0,2)
for ie=1:size(b0,1)-1
if b0(ie,ib)>0 && b0(ie+1,ib)<=0 || b0(ie,ib)<0 && b0(ie+1,ib)>=0
%if b0(ie)>0 && b0(ie+1)<=0 || b0(ie)<0 && b0(ie+1)>=0
Z=ee(ie);
ZZ=[ZZ Z];l=min(ZZ);
end
end end
0 comentarios
Respuesta aceptada
Star Strider
el 30 de Jul. de 2015
I am not certain what you want, but this will give you the row indices in each column where the sign changes:
b0=[1,2,3,-2,-3,7;3,4,7,-5,-3,4,;-3,-4,6,7,-1,-2]';
ee=[1 2 3 4 5 6];plot(ee,b0')
sc_idx = (b0 .* circshift(b0, [1 0]) < 0); % Circularl Shift To Detect Sign Changes
[sc_posr, sc_posc] = find( sc_idx ); % Find Rows & Columns Of Sign Changes
ZZ = reshape(sc_posr, [], size(b0,2)); % Matrix Of Row Indices Of Sign Changes, By Column
ZZ =
4 4 3
6 6 5
6 comentarios
Más respuestas (1)
Brendan Hamm
el 30 de Jul. de 2015
If you find the logical condition of the locations in b0 where the value is greater than or equal to zero, you can find the location of sign changes by taking the difference of each row with the previous row. A sign change would then have a value of +1 or -1 (or rather the non-zero values).
idxP = b0 >= 0; % Logical vector of non-negative values
diff(idxP) ~= 0
ans =
0 0 0 0 0 0
1 1 0 1 0 1
So where this condition is true we have a 1 (true) value. So for the first curve (column 1) we can see a sign change occurs from the 2nd to 3rd entry.
Ver también
Categorías
Más información sobre Historical Contests en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!