Info
This question is closed. Reopen it to edit or answer.
Building a switch so allow&forbid a signal
1 view (last 30 days)
Show older comments
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.
3 Comments
Jan
on 19 Jan 2013
The pre-allocation is important for efficient code:
cuttingforce = zeros(1, length(Tsoll));
Not cuttingforce(i).
Image Analyst
on 19 Jan 2013
What is Fzerspan? And in your latest comment, cuttingforce = 0 if the condition is met but at the start you set it to 1. So I wasn't quite sure what to do in my vectorized answer below.
Answers (1)
Image Analyst
on 19 Jan 2013
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;
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!