Hey! I would like to create a kind of switch that allows the exsistence of a signal under specific circumstances in MatLab. There are about 91.000 checkpoints in which the switch has to operate to give an answer to the question: does contact exsist? It should say either "yes" (1) or "no" (0) for each of these 91.000 checkpoints.
There is the position of a tool which is declared to be Xsollf(i),Ysollf(i),Zsollf(i) which is variable in time and the position data of a work piece which reaches from X1 to X2, Y1 to Y2 and Z1 to Z2 which is fixed.
So now i tried something like this:
cuttingforce(i) = zeros(1,length(Tsoll)); % Tsoll is the vector of time
for i = 2:length(Tsoll)
if Z1<Zsollf(i) && Zsollf(i) <Z2 && Y1<Ysollf(i) && Ysollf(i) <Y2 && X1<Xsollf(i) && Xsollf(i)<X2 cuttingforce(i)=1; end % of if end %of for
I wanted to use &&-operator that saves a little bit of time by stopping the examination whenever one of these if conditions is flase. Each time the if conditions are true which means the tool is on the surface of the work piece or within its body the element of the cutting force vector should be changed from 0 to 1 so that there can exsist cutting force.
I am just an amateur and by now I just can not find a solution. I would be grateful to read your ideas.
Try this vectorized way:
cuttingforce = zeros(1, length(Tsoll)); Fzerspan = zeros(1, length(Tsoll)) inRange = Z1 < Zsollf(i) && Zsollf(i) < Z2 &&... Y1 < Ysollf(i) && Ysollf(i) < Y2 &&... X1 < Xsollf(i) && Xsollf(i) < X2) % If in range, set Fzerspan and cuttingforce. Fzerspan(inRange) = 1; cuttingforce(inRange) = 1;