Assigning a list of numbers to their corresponding cells in a mesh
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello all,
I have the mesh as showing below. The cells index vector is right next to it.
If I have a vector of y values: , that has four elements. Each element corresponds to a vertical cell in the mesh where the x index of the first is 1, the second is 2, and so on. The cells that correspond to this y vector is:
I need to write a code that decide the cell for each of these elements and create a vector that contains them, as shown above. My attempt of doing it is as follwoing:
MidPoint = 4; %number of midpoints
ycells = 4; %number of cells on the y edge
Mid_y = [0.1250 0.3750 0.6250 0.8750]; %values of midpoints
dy = 0.1250; %the step
y = [0.52 0.68 0.19 0.46] %the new set of y values that need to decide their cells
for i = 1:MidPoint
for j = 1:ycells
if y(i) <= Mid_y(j)+dy && y(i) >= Mid_y(j)-dy
Cells = Cells(i*j)
end
end
end
Any help would be appreicted.
Thanks.
댓글 수: 0
채택된 답변
Voss
2022년 7월 5일
Is something like this what you're after?
MidPoint = 4; %number of midpoints
ycells = 4; %number of cells on the y edge
Mid_y = [0.1250 0.3750 0.6250 0.8750]; %values of midpoints
dy = 0.1250; %the step
y = [0.52 0.68 0.19 0.46] %the new set of y values that need to decide their cells
for i = 1:MidPoint
for j = 1:ycells
% have to decide how to handle the case that y(i) is on the edge
% between two cells; don't want to count that as belonging to
% more than one cell, so use < and >= (or <= and >):
if y(i) < Mid_y(j)+dy && y(i) >= Mid_y(j)-dy
% assign 10*i+j to element i of Cell:
Cells(i,1) = 10*i + j;
% stop looking when you find the cell that y(i) belongs to:
break
end
end
end
disp(Cells)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Weather and Atmospheric Science에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!