Display in the command window
조회 수: 2 (최근 30일)
이전 댓글 표시
my code looks as follows but i don't understand why the values of x and z won't display on the command window. The values are supposed to plot a semicircle.
startUpHeight = 299.07;
startUpValue = 100;
radius = 15;
minConstraintX = 150;
maxConstraintX = 50;
minConstraintZ = 10;
maxConstraintZ = 300;
for x = (startUpValue - radius):0.25:(startUpValue + radius)
if ((maxConstraintX >= x) && (x >= minConstraintX))
z = -1*((sqrt(radius^2)-((x-(3*radius))^2)) - startUpHeight);
if ((maxConstraintZ >= z) && (z >= minConstraintZ))
disp(['x: ', num2str(x), ', z: ', num2str(z)]);
end
end
end
댓글 수: 0
채택된 답변
Athanasios Paraskevopoulos
2024년 5월 15일
startUpHeight = 299.07;
startUpValue = 100;
radius = 15;
minConstraintX = 50; % Swapped values
maxConstraintX = 150; % Swapped values
minConstraintZ = 10;
maxConstraintZ = 300;
for x = (startUpValue - radius) : 0.25 : (startUpValue + radius)
if ((maxConstraintX >= x) && (x >= minConstraintX))
z = startUpHeight - sqrt(radius^2 - ((x - startUpValue)^2)); % Corrected formula for z
if ((maxConstraintZ >= z) && (z >= minConstraintZ))
disp(['x: ', num2str(x), ', z: ', num2str(z)]);
end
end
end
댓글 수: 0
추가 답변 (1개)
Image Analyst
2024년 5월 15일
You swapped the min and max x constraints. Even when I fix those, the z constraint is not met. I threw in some debug messages so you can see what's going on:
startUpHeight = 299.07;
startUpValue = 100;
radius = 15;
minConstraintX = 50;
maxConstraintX = 150;
minConstraintZ = 10;
maxConstraintZ = 300;
z = 0;
for x = (startUpValue - radius):0.25:(startUpValue + radius)
if ((maxConstraintX >= x) && (x >= minConstraintX))
z = -1*((sqrt(radius^2)-((x-(3*radius))^2)) - startUpHeight);
if ((maxConstraintZ >= z) && (z >= minConstraintZ))
% Constraints met
fprintf('Both X and Z Constraints ARE met. x: %f, z: %f\n', x, z);
else
% Z Constraints not met:
fprintf('Z Constraint IS NOT met. x: %f, z: %f\n', x, z);
end
else
% X Constraints not met:
fprintf('X Constraint IS NOT met. x: %f, z: %f\n', x, z);
end
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!