# Setting values in a column using multiple if else statements

조회 수: 2(최근 30일)
Rahul Gulia 2022년 9월 28일
I hope I can describe my problem in simple words.
This is a top view of a warehouse of size 60x55 m. And I have placed shelves in the warehouse of dimension 2.5x20 m.
I have to create a column that displays the distance of each location from the nearest shelf. And this is what I have done right now.
Here, (nx,1) column refers to the x-position, and (nx,2) column refers to the y-position in the warehouse.
for nx=1:length(DatasetTmp_10)
% Adding the data for within shelf coverage (Within the shelf area, value = 0)
if ((DatasetTmp_10(nx,1)>=5 & DatasetTmp_10(nx,1)<=7.3)|(DatasetTmp_10(nx,1)>=10.3 & DatasetTmp_10(nx,1)<=12.6)...
|(DatasetTmp_10(nx,1)>=15.6 & DatasetTmp_10(nx,1)<=17.9)|(DatasetTmp_10(nx,1)>=20.9 & DatasetTmp_10(nx,1)<=23.2)...
|(DatasetTmp_10(nx,1)>=26.2 & DatasetTmp_10(nx,1)<=28.5)|(DatasetTmp_10(nx,1)>=31.5 & DatasetTmp_10(nx,1)<=33.8)...
|(DatasetTmp_10(nx,1)>=36.8 & DatasetTmp_10(nx,1)<=39.1)|(DatasetTmp_10(nx,1)>=42.1 & DatasetTmp_10(nx,1)<=44.4)...
|(DatasetTmp_10(nx,1)>=47.4 & DatasetTmp_10(nx,1)<=49.7)|(DatasetTmp_10(nx,1)>=52.7 & DatasetTmp_10(nx,1)<=55))
DatasetTmp_10(nx,14) = 0;
% In the aisle coverage (if they are inside an aisle, calculate the distance to the nearest aisle, and substitute the value)
% Here I am calculating the distance from a location from its right and left side kept shelf.
elseif ((DatasetTmp_10(nx,1)>=7.3 & DatasetTmp_10(nx,1)<=10.3))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,1)-7.3),(10.3-DatasetTmp_10(nx,1)));
elseif ((DatasetTmp_10(nx,1)>=12.6 & DatasetTmp_10(nx,1)<=15.6))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,1)-12.6),(15.6-DatasetTmp_10(nx,1)));
elseif ((DatasetTmp_10(nx,1)>=17.9 & DatasetTmp_10(nx,1)<=20.9))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,1)-17.9),(20.9-DatasetTmp_10(nx,1)));
elseif ((DatasetTmp_10(nx,1)>=23.2 & DatasetTmp_10(nx,1)<=26.2))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,1)-23.2),(26.2-DatasetTmp_10(nx,1)));
elseif ((DatasetTmp_10(nx,1)>=28.5 & DatasetTmp_10(nx,1)<=31.5))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,1)-28.5),(31.5-DatasetTmp_10(nx,1)));
elseif ((DatasetTmp_10(nx,1)>=33.8 & DatasetTmp_10(nx,1)<=36.8))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,1)-33.8),(36.8-DatasetTmp_10(nx,1)));
elseif ((DatasetTmp_10(nx,1)>=42.1 & DatasetTmp_10(nx,1)<=47.4))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,1)-42.1),(47.4-DatasetTmp_10(nx,1)));
elseif ((DatasetTmp_10(nx,1)>=49.7 & DatasetTmp_10(nx,1)<=52.7))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,1)-49.7),(52.7-DatasetTmp_10(nx,1)));
% Corner Aisles data
elseif ((DatasetTmp_10(nx,1)>=0 & DatasetTmp_10(nx,1)<=5)) % Left corner aisle
DatasetTmp_10(nx,14) = 5-DatasetTmp_10(nx,1);
elseif ((DatasetTmp_10(nx,1)>=55 & DatasetTmp_10(nx,1)<=60)) % Right corner aisle
DatasetTmp_10(nx,14) = DatasetTmp_10(nx,1)-55;
% Strong LOS cases (East-West Direction)
elseif ((DatasetTmp_10(nx,2)>=0 & DatasetTmp_10(nx,2)<=5)&&((DatasetTmp_10(nx,1)>=0 & DatasetTmp_10(nx,1)<=60)))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,2)-0),(5-DatasetTmp_10(nx,1)));
elseif ((DatasetTmp_10(nx,2)>=25 & DatasetTmp_10(nx,2)<=30)&&((DatasetTmp_10(nx,1)>=0 & DatasetTmp_10(nx,1)<=60)))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,2)-25),(30-DatasetTmp_10(nx,1)));
elseif ((DatasetTmp_10(nx,2)>=50 & DatasetTmp_10(nx,2)<=55)&&((DatasetTmp_10(nx,1)>=0 & DatasetTmp_10(nx,1)<=60)))
DatasetTmp_10(nx,14) = min((DatasetTmp_10(nx,2)-50),(55-DatasetTmp_10(nx,1)));
else
DatasetTmp_10(nx,14) = NaN; % Putting Null data in here
end
end
I think I have overlapping if else conditions for multiple positions.
I would really appreciate it if someone could suggest on my code, and help me find a better solution to construct a more accurate data for my scenario.
Looking forward to any kind of suggestion.
Thank You

댓글을 달려면 로그인하십시오.

### 범주

Find more on Model Compatibility Checks 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!

Translated by