Application of Logical operators

1 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2022-10-3
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 个评论
Rahul Gulia
Rahul Gulia 2022-10-3
Thank you for the suggestion @Star Strider. I will look into these functions of the MATLAB.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by