I've written some code to monitor a mock retail outlet which loads product location (x/y) data from a .xls file and plots it on top the stores blueprint.
the blueprint has defined payment and exit areas, and each product has a payment status variable (P#pay) where 0 = unpaid and 1 = paid. If the product enters the payment area the paystatus variable changes from 0 to 1. I wrote a for/if statement to handle this operation but it's not working properly and I cant seem to figure out why. Below is the code, and thanks for taking the time to look this over!
% Blank, Jacob
clear allclose allclc%define store dimensions blueprint
hold on rectangle('position',[0,0,120,110])%define shelving units
rectangle('position',[15,20,10,75],'facecolor','y') rectangle('position',[35,20,10,75],'facecolor','y') rectangle('position',[55,20,10,75],'facecolor','y') rectangle('position',[75,10,10,30],'facecolor','y') rectangle('position',[90,10,10,30],'facecolor','y') rectangle('position',[105,10,10,30],'facecolor','y')%define freezer space
rectangle('position',[75,75,40,15],'facecolor','c') rectangle('position',[75,50,40,15],'facecolor','c')%define payment portal
rectangle('position',[15,0,20,10],'facecolor','g') text(21,5,'PAY') payYlimMax=10; payYlimMin=0; payXlimMax=35; payXlimMin=15;%define exit
rectangle('position',[0,0,15,10],'facecolor','r') text(2,5,'EXT') extYlimMax=10; extYlimMin=0; extXlimMax=15; extXlimMin=0; axis on%product 1 location data
P1 = xlsread('location_data','Product 1'); n=size(P1,1); P1X=P1(2:n,1); P1Y=P1(2:n,2); plot(P1X,P1Y,'ko');%product 1 payment status
P1pay=0; for i=1:n-1 if payXlimMin < P1X(i) < payXlimMax && payYlimMin < P1Y(i) < payYlimMax P1pay = 1; end end %product 2 location data
P2 = xlsread('location_data','Product 2'); n2=size(P2,1); P2X=P2(2:n2,1); P2Y=P2(2:n2,2); plot(P2X,P2Y,'ko');%product 2 payment status
P2pay=0; for i2=1:n2-1 if payXlimMin < P2X(i2) < payXlimMax && payYlimMin < P2Y(i2) < payYlimMax P2pay = 1 end end hold off
Best Answer