How to make a custom slider to adjust theta?
12 次查看(过去 30 天)
显示 更早的评论
So I have this code:
% move left_upper_arm
% rotate left_upper_arm
theta = -10;
trans = [cosd(theta), sind(theta); -sind(theta), cosd(theta)];
tmp = trans*cell2mat(skeleton(2));
dxy = tmp - cell2mat(skeleton(2));
skeleton(2) = mat2cell(tmp,2,2);
%move left_fore_arm accordingly
dxy = dxy(:,2);
skeleton(3) = mat2cell(cell2mat(skeleton(3)) + dxy,2,2);
% move and rotate left_forearm
theta = -10;
trans = [cosd(theta), sind(theta); -sind(theta), cosd(theta)];
coor = cell2mat(skeleton(3));
new_coor = coor - coor(:,1);
new_coor = trans*new_coor;
new_coor = new_coor + coor(:,1);
skeleton(3) = mat2cell(new_coor,2,2);
% plot
clf
figure(1)
hold on;
for i = 1:10
tmp = cell2mat(skeleton(i));
plot(tmp(1,1:end), tmp(2,1:end),'*b-')
end
How to make the theta into a adjustable slider where you can manually slide it and change the angle? The slider should appear in the code editor right next to the "theta = ", and the value of theta should immediately change to where your slider is at. The max of the slider should be 180 and min should be -180.
Thank you
0 个评论
回答(2 个)
Arka
2023-2-10
编辑:Arka
2023-2-10
Hi,
From what I understood, you want to convert the theta variable to a slider, and the variable can have values ranging from -180 to 180.
You can achieve this by using a MATLAB Live Script instead of a MATLAB Script.
Go to the MATLAB Window, then click on the arrow under New. Then click on Live Script. A new Live Script will open.
Paste your code there. Then click on LIVE EDITOR in the ribbon at the top of the MATLAB window.
Select the value of the theta variable. You will see a Control option under the LIVE EDITOR options. Click on it. Then click on Numeric Slider. The variable gets converted to a slider.
Right click on the slider and click on Configure Control from the pop-up menu. From here, you can adjust the starting value, minimum and maximum value, step size, label, and a couple of more things.
At the end, the variable will look like this:
Refer to the below documentations for more information about Live Script and interactive controls:
0 个评论
Sulaymon Eshkabilov
2023-2-10
(1) Copy and paste your code into MLX-editor
(2) Bring your cursor before theta
(3) Click on the LIVE EDITOR Pane
(4) Click on Control
(5) Select Numeric Slider
(6) Type in Label: theta - see attached screenshot
(7) Adjust min, max and step values
Now a slider is ready to run in MLX-editor
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!