Application of Logical operators

Hi team,
I am trying to assign a colour to each part of this simple warehouse diagram with 4 shelves.
I have to assign a unique value to each part of this model, i.e., for the 4 shelves location, the aisles location, the warehouse corners.
I have tried to use logical operators to assign a colour to each part of the warehouse model. But I am having issues to do that properly. Kindly help.
My code:
clc;
clear all;
close all;
x_pos_tmp = 0:0.05:10;
y_pos_tmp = 0:0.05:5;
x_pos = repelem(x_pos_tmp,1,length(y_pos_tmp))';
y_pos = repmat(y_pos_tmp,1,length(x_pos_tmp))';
mat = [x_pos y_pos];
%% Shelf distance column
tmp1 = zeros(1,length(mat))';
matTmp = [mat tmp1];
for nx=1:length(mat)
% Adding the data for within shelf coverage
if ((mat(nx,1)>=1.1 && matTmp(nx,1)<=1.9)&&(matTmp(nx,2)>=1.1 && matTmp(nx,2)<=3.9))
matTmp(nx,3) = 50;
elseif ((matTmp(nx,1)>=3.1 && matTmp(nx,1)<=3.9)&&(matTmp(nx,2)>=1.1 && matTmp(nx,2)<=3.9))
matTmp(nx,3) = 50;
elseif ((matTmp(nx,1)>=5.1 && matTmp(nx,1)<=5.9)&&(matTmp(nx,2)>=1.1 && matTmp(nx,2)<=3.9))
matTmp(nx,3) = 50;
elseif ((matTmp(nx,1)>=7.1 && matTmp(nx,1)<=7.9)&&(matTmp(nx,2)>=1.1 && matTmp(nx,2)<=3.9))
matTmp(nx,3) = 50;
% In the aisle coverage
elseif ((matTmp(nx,1)>=2.1 && matTmp(nx,1)<=2.9)&&(matTmp(nx,2)>=1.1 && matTmp(nx,2)<=3.9))
% matTmp(nx,3) = min((matTmp(nx,1)-2),(3-matTmp(nx,1)));
matTmp(nx,3) = 100;
elseif ((matTmp(nx,1)>=4.1 && matTmp(nx,1)<=4.9)&&(matTmp(nx,2)>=1.1 && matTmp(nx,2)<=3.9))
% matTmp(nx,3) = min((matTmp(nx,1)-4),(5-matTmp(nx,1)));
matTmp(nx,3) = 100;
elseif ((matTmp(nx,1)>=6.1 && matTmp(nx,1)<=6.9)&&(matTmp(nx,2)>=1.1 && matTmp(nx,2)<=3.9))
% matTmp(nx,3) = min((matTmp(nx,1)-6),(7-matTmp(nx,1)));
matTmp(nx,3) = 100;
% Corner Aisles data
elseif ((matTmp(nx,1)>=0 && matTmp(nx,1)<=0.9)&&(matTmp(nx,2)>=0 && matTmp(nx,2)<=5)) % Left corner aisle
% matTmp(nx,3) = 1-matTmp(nx,1);
matTmp(nx,3) = 150;
elseif ((matTmp(nx,1)>=7.9 && matTmp(nx,1)<=10)&&(matTmp(nx,2)>=0 && matTmp(nx,2)<=5)) % Right corner aisle
% matTmp(nx,3) = matTmp(nx,1)-8;
matTmp(nx,3) = 150;
% Strong LOS cases (East-West Direction)
elseif ((matTmp(nx,1)>=1.1 && matTmp(nx,1)<=7.9)&&(matTmp(nx,2)>=0 && matTmp(nx,2)<=0.9))
% matTmp(nx,3) = min((matTmp(nx,2)-0),(1-matTmp(nx,1)));
matTmp(nx,3) = 200;
elseif ((matTmp(nx,1)>=1.1 && matTmp(nx,1)<=7.9)&&((matTmp(nx,2)>=4.1 && matTmp(nx,2)<=5)))
% matTmp(nx,3) = min((matTmp(nx,2)-4),(5-matTmp(nx,1)));
matTmp(nx,3) = 200;
else
matTmp(nx,3) = 0;
end
end
%% Plot
data = reshape(matTmp(:,3),length(x_pos_tmp),length(y_pos_tmp));
figure(1)
set(gca,'DefaultTextFontSize',14)
imagesc(0:10,0:5, data); % 0:0.5:18,0:0.1:30,
xlabel('X-distance [m]','FontSize',14);
ylabel('Y-distance [m]','FontSize',14);
set(gca,'YDir','normal');
a=colorbar;
% a.Label.String = 'SINR [dB]';
ylabel(a,'SINR [dB]','FontSize',14)
colormap jet;
% clim([20 90])
--------------------------------------------------------------------------------------------------------------------------------------------------------
Output:
This plot should look like the first figure. Looking forward to any kind of suggestions.
Thank You,
Rahul Singh Gulia

 Accepted Answer

Perhaps something like this —
figure
hold on
for k = 1:4
patch([1 2 2 1]+2*(k-1), [1 1 4 4], 'b', 'FaceAlpha',0.5)
text(1.5+2*(k-1), 2.5, sprintf('Shelf %d',k), 'Horiz','center', 'Vert','middle', 'FontSize',8)
end
hold off
axis([0 10 0 5])
Ax = gca;
Ax.Color = [1 1 1]*0.9;
.

6 Comments

Thank you for the suggestion @Star Strider. This is really good.
But I want to access those locations and insert a new set of values (i.e., the colour codes) to create a new column in the dataset.
Please let me know if I can do this using the logical operator to solve my issue.
Thank you for the suggestion.
My pleasure.
I cannot understand your code. What specifically do you want to do?
I want to access each point in the warehouse, and assign a distance value from the nearest shelf in the aisle.
I have commented those lines that calculate the distance from the nearest shelf.
% In the aisle coverage
elseif ((matTmp(nx,1)>=2.1 && matTmp(nx,1)<=2.9)&&(matTmp(nx,2)>=1.1 && matTmp(nx,2)<=3.9))
% matTmp(nx,3) = min((matTmp(nx,1)-2),(3-matTmp(nx,1)));
matTmp(nx,3) = 100;
I hope this makes it clear.
It doesn’t, unfortunately. There are several ways to calculate distance, not all of which might be appropriate for your problem, since the only ones I’m reasonably familiar with involve straight-line distances, and that would require going through the shelves. (Physics generally discourages those sorts of solutions.)
It might be worthwhile to do this as a graph or digraph problem and then use the shortestpath or similar approaches (listed in the See Also section of that documentation) to determine the distances. The Robotics Toolbox (that I don’t have and so have no experience with its functions) might also have some options.
Thank you for the suggestion @Star Strider. I will look into these functions of the MATLAB.
My pleasure!

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!