Display in the command window

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

 Accepted Answer

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
x: 85, z: 299.07 x: 85.25, z: 296.3428 x: 85.5, z: 295.2294 x: 85.75, z: 294.3863 x: 86, z: 293.6848 x: 86.25, z: 293.0752 x: 86.5, z: 292.5317 x: 86.75, z: 292.0388 x: 87, z: 291.5867 x: 87.25, z: 291.1683 x: 87.5, z: 290.7784 x: 87.75, z: 290.4134 x: 88, z: 290.07 x: 88.25, z: 289.746 x: 88.5, z: 289.4393 x: 88.75, z: 289.1484 x: 89, z: 288.872 x: 89.25, z: 288.6088 x: 89.5, z: 288.3579 x: 89.75, z: 288.1184 x: 90, z: 287.8897 x: 90.25, z: 287.671 x: 90.5, z: 287.4618 x: 90.75, z: 287.2616 x: 91, z: 287.07 x: 91.25, z: 286.8865 x: 91.5, z: 286.7108 x: 91.75, z: 286.5425 x: 92, z: 286.3814 x: 92.25, z: 286.2272 x: 92.5, z: 286.0796 x: 92.75, z: 285.9385 x: 93, z: 285.8035 x: 93.25, z: 285.6746 x: 93.5, z: 285.5515 x: 93.75, z: 285.4341 x: 94, z: 285.3223 x: 94.25, z: 285.2158 x: 94.5, z: 285.1147 x: 94.75, z: 285.0188 x: 95, z: 284.9279 x: 95.25, z: 284.8419 x: 95.5, z: 284.7609 x: 95.75, z: 284.6847 x: 96, z: 284.6132 x: 96.25, z: 284.5463 x: 96.5, z: 284.484 x: 96.75, z: 284.4263 x: 97, z: 284.3731 x: 97.25, z: 284.3242 x: 97.5, z: 284.2798 x: 97.75, z: 284.2397 x: 98, z: 284.2039 x: 98.25, z: 284.1724 x: 98.5, z: 284.1452 x: 98.75, z: 284.1222 x: 99, z: 284.1034 x: 99.25, z: 284.0888 x: 99.5, z: 284.0783 x: 99.75, z: 284.0721 x: 100, z: 284.07 x: 100.25, z: 284.0721 x: 100.5, z: 284.0783 x: 100.75, z: 284.0888 x: 101, z: 284.1034 x: 101.25, z: 284.1222 x: 101.5, z: 284.1452 x: 101.75, z: 284.1724 x: 102, z: 284.2039 x: 102.25, z: 284.2397 x: 102.5, z: 284.2798 x: 102.75, z: 284.3242 x: 103, z: 284.3731 x: 103.25, z: 284.4263 x: 103.5, z: 284.484 x: 103.75, z: 284.5463 x: 104, z: 284.6132 x: 104.25, z: 284.6847 x: 104.5, z: 284.7609 x: 104.75, z: 284.8419 x: 105, z: 284.9279 x: 105.25, z: 285.0188 x: 105.5, z: 285.1147 x: 105.75, z: 285.2158 x: 106, z: 285.3223 x: 106.25, z: 285.4341 x: 106.5, z: 285.5515 x: 106.75, z: 285.6746 x: 107, z: 285.8035 x: 107.25, z: 285.9385 x: 107.5, z: 286.0796 x: 107.75, z: 286.2272 x: 108, z: 286.3814 x: 108.25, z: 286.5425 x: 108.5, z: 286.7108 x: 108.75, z: 286.8865 x: 109, z: 287.07 x: 109.25, z: 287.2616 x: 109.5, z: 287.4618 x: 109.75, z: 287.671 x: 110, z: 287.8897 x: 110.25, z: 288.1184 x: 110.5, z: 288.3579 x: 110.75, z: 288.6088 x: 111, z: 288.872 x: 111.25, z: 289.1484 x: 111.5, z: 289.4393 x: 111.75, z: 289.746 x: 112, z: 290.07 x: 112.25, z: 290.4134 x: 112.5, z: 290.7784 x: 112.75, z: 291.1683 x: 113, z: 291.5867 x: 113.25, z: 292.0388 x: 113.5, z: 292.5317 x: 113.75, z: 293.0752 x: 114, z: 293.6848 x: 114.25, z: 294.3863 x: 114.5, z: 295.2294 x: 114.75, z: 296.3428 x: 115, z: 299.07

More Answers (1)

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
Z Constraint IS NOT met. x: 85.000000, z: 1884.070000 Z Constraint IS NOT met. x: 85.250000, z: 1904.132500 Z Constraint IS NOT met. x: 85.500000, z: 1924.320000 Z Constraint IS NOT met. x: 85.750000, z: 1944.632500 Z Constraint IS NOT met. x: 86.000000, z: 1965.070000 Z Constraint IS NOT met. x: 86.250000, z: 1985.632500 Z Constraint IS NOT met. x: 86.500000, z: 2006.320000 Z Constraint IS NOT met. x: 86.750000, z: 2027.132500 Z Constraint IS NOT met. x: 87.000000, z: 2048.070000 Z Constraint IS NOT met. x: 87.250000, z: 2069.132500 Z Constraint IS NOT met. x: 87.500000, z: 2090.320000 Z Constraint IS NOT met. x: 87.750000, z: 2111.632500 Z Constraint IS NOT met. x: 88.000000, z: 2133.070000 Z Constraint IS NOT met. x: 88.250000, z: 2154.632500 Z Constraint IS NOT met. x: 88.500000, z: 2176.320000 Z Constraint IS NOT met. x: 88.750000, z: 2198.132500 Z Constraint IS NOT met. x: 89.000000, z: 2220.070000 Z Constraint IS NOT met. x: 89.250000, z: 2242.132500 Z Constraint IS NOT met. x: 89.500000, z: 2264.320000 Z Constraint IS NOT met. x: 89.750000, z: 2286.632500 Z Constraint IS NOT met. x: 90.000000, z: 2309.070000 Z Constraint IS NOT met. x: 90.250000, z: 2331.632500 Z Constraint IS NOT met. x: 90.500000, z: 2354.320000 Z Constraint IS NOT met. x: 90.750000, z: 2377.132500 Z Constraint IS NOT met. x: 91.000000, z: 2400.070000 Z Constraint IS NOT met. x: 91.250000, z: 2423.132500 Z Constraint IS NOT met. x: 91.500000, z: 2446.320000 Z Constraint IS NOT met. x: 91.750000, z: 2469.632500 Z Constraint IS NOT met. x: 92.000000, z: 2493.070000 Z Constraint IS NOT met. x: 92.250000, z: 2516.632500 Z Constraint IS NOT met. x: 92.500000, z: 2540.320000 Z Constraint IS NOT met. x: 92.750000, z: 2564.132500 Z Constraint IS NOT met. x: 93.000000, z: 2588.070000 Z Constraint IS NOT met. x: 93.250000, z: 2612.132500 Z Constraint IS NOT met. x: 93.500000, z: 2636.320000 Z Constraint IS NOT met. x: 93.750000, z: 2660.632500 Z Constraint IS NOT met. x: 94.000000, z: 2685.070000 Z Constraint IS NOT met. x: 94.250000, z: 2709.632500 Z Constraint IS NOT met. x: 94.500000, z: 2734.320000 Z Constraint IS NOT met. x: 94.750000, z: 2759.132500 Z Constraint IS NOT met. x: 95.000000, z: 2784.070000 Z Constraint IS NOT met. x: 95.250000, z: 2809.132500 Z Constraint IS NOT met. x: 95.500000, z: 2834.320000 Z Constraint IS NOT met. x: 95.750000, z: 2859.632500 Z Constraint IS NOT met. x: 96.000000, z: 2885.070000 Z Constraint IS NOT met. x: 96.250000, z: 2910.632500 Z Constraint IS NOT met. x: 96.500000, z: 2936.320000 Z Constraint IS NOT met. x: 96.750000, z: 2962.132500 Z Constraint IS NOT met. x: 97.000000, z: 2988.070000 Z Constraint IS NOT met. x: 97.250000, z: 3014.132500 Z Constraint IS NOT met. x: 97.500000, z: 3040.320000 Z Constraint IS NOT met. x: 97.750000, z: 3066.632500 Z Constraint IS NOT met. x: 98.000000, z: 3093.070000 Z Constraint IS NOT met. x: 98.250000, z: 3119.632500 Z Constraint IS NOT met. x: 98.500000, z: 3146.320000 Z Constraint IS NOT met. x: 98.750000, z: 3173.132500 Z Constraint IS NOT met. x: 99.000000, z: 3200.070000 Z Constraint IS NOT met. x: 99.250000, z: 3227.132500 Z Constraint IS NOT met. x: 99.500000, z: 3254.320000 Z Constraint IS NOT met. x: 99.750000, z: 3281.632500 Z Constraint IS NOT met. x: 100.000000, z: 3309.070000 Z Constraint IS NOT met. x: 100.250000, z: 3336.632500 Z Constraint IS NOT met. x: 100.500000, z: 3364.320000 Z Constraint IS NOT met. x: 100.750000, z: 3392.132500 Z Constraint IS NOT met. x: 101.000000, z: 3420.070000 Z Constraint IS NOT met. x: 101.250000, z: 3448.132500 Z Constraint IS NOT met. x: 101.500000, z: 3476.320000 Z Constraint IS NOT met. x: 101.750000, z: 3504.632500 Z Constraint IS NOT met. x: 102.000000, z: 3533.070000 Z Constraint IS NOT met. x: 102.250000, z: 3561.632500 Z Constraint IS NOT met. x: 102.500000, z: 3590.320000 Z Constraint IS NOT met. x: 102.750000, z: 3619.132500 Z Constraint IS NOT met. x: 103.000000, z: 3648.070000 Z Constraint IS NOT met. x: 103.250000, z: 3677.132500 Z Constraint IS NOT met. x: 103.500000, z: 3706.320000 Z Constraint IS NOT met. x: 103.750000, z: 3735.632500 Z Constraint IS NOT met. x: 104.000000, z: 3765.070000 Z Constraint IS NOT met. x: 104.250000, z: 3794.632500 Z Constraint IS NOT met. x: 104.500000, z: 3824.320000 Z Constraint IS NOT met. x: 104.750000, z: 3854.132500 Z Constraint IS NOT met. x: 105.000000, z: 3884.070000 Z Constraint IS NOT met. x: 105.250000, z: 3914.132500 Z Constraint IS NOT met. x: 105.500000, z: 3944.320000 Z Constraint IS NOT met. x: 105.750000, z: 3974.632500 Z Constraint IS NOT met. x: 106.000000, z: 4005.070000 Z Constraint IS NOT met. x: 106.250000, z: 4035.632500 Z Constraint IS NOT met. x: 106.500000, z: 4066.320000 Z Constraint IS NOT met. x: 106.750000, z: 4097.132500 Z Constraint IS NOT met. x: 107.000000, z: 4128.070000 Z Constraint IS NOT met. x: 107.250000, z: 4159.132500 Z Constraint IS NOT met. x: 107.500000, z: 4190.320000 Z Constraint IS NOT met. x: 107.750000, z: 4221.632500 Z Constraint IS NOT met. x: 108.000000, z: 4253.070000 Z Constraint IS NOT met. x: 108.250000, z: 4284.632500 Z Constraint IS NOT met. x: 108.500000, z: 4316.320000 Z Constraint IS NOT met. x: 108.750000, z: 4348.132500 Z Constraint IS NOT met. x: 109.000000, z: 4380.070000 Z Constraint IS NOT met. x: 109.250000, z: 4412.132500 Z Constraint IS NOT met. x: 109.500000, z: 4444.320000 Z Constraint IS NOT met. x: 109.750000, z: 4476.632500 Z Constraint IS NOT met. x: 110.000000, z: 4509.070000 Z Constraint IS NOT met. x: 110.250000, z: 4541.632500 Z Constraint IS NOT met. x: 110.500000, z: 4574.320000 Z Constraint IS NOT met. x: 110.750000, z: 4607.132500 Z Constraint IS NOT met. x: 111.000000, z: 4640.070000 Z Constraint IS NOT met. x: 111.250000, z: 4673.132500 Z Constraint IS NOT met. x: 111.500000, z: 4706.320000 Z Constraint IS NOT met. x: 111.750000, z: 4739.632500 Z Constraint IS NOT met. x: 112.000000, z: 4773.070000 Z Constraint IS NOT met. x: 112.250000, z: 4806.632500 Z Constraint IS NOT met. x: 112.500000, z: 4840.320000 Z Constraint IS NOT met. x: 112.750000, z: 4874.132500 Z Constraint IS NOT met. x: 113.000000, z: 4908.070000 Z Constraint IS NOT met. x: 113.250000, z: 4942.132500 Z Constraint IS NOT met. x: 113.500000, z: 4976.320000 Z Constraint IS NOT met. x: 113.750000, z: 5010.632500 Z Constraint IS NOT met. x: 114.000000, z: 5045.070000 Z Constraint IS NOT met. x: 114.250000, z: 5079.632500 Z Constraint IS NOT met. x: 114.500000, z: 5114.320000 Z Constraint IS NOT met. x: 114.750000, z: 5149.132500 Z Constraint IS NOT met. x: 115.000000, z: 5184.070000

Categories

Find more on Graphics Objects in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!