Display in the command window
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Manuel
am 15 Mai 2024
Beantwortet: Image Analyst
am 15 Mai 2024
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 Kommentare
Akzeptierte Antwort
Athanasios Paraskevopoulos
am 15 Mai 2024
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 Kommentare
Weitere Antworten (1)
Image Analyst
am 15 Mai 2024
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 Kommentare
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!