MATLAB-向图形添加已校准的滑块

如何解决MATLAB-向图形添加已校准的滑块

我正在尝试向该图添加一个经过校准的滑块。 它是一个带有3d冲浪图的人物框架。

enter image description here

现在您可以看到,我设法使用“ uicontrol”命令创建了一个滑块,但是我无法对其进行校准,也无法在其上创建任何刻度。

我尝试使用“ uislider”来创建一个漂亮的滑块,就像我想要的滑块一样,但是由于某种原因,我无法在图中添加其中一个滑块(仅当我使用uifigure创建原始图时才有效)这样做我无法在其中绘制冲浪图,我也不知道为什么。)

这是我的代码。

主脚本。

clear vars
filename = ('C:\Users\Ali\Desktop\Documents\DataVis\Projekt\data\day\filenames.txt');
%This line simply gives us a table of all filenames in this file.
T = readtable(filename);
tsize = size(T);
tsize2 = size(T,1);

%initialize figure.
mainFigure = figure('name','CylinderHeatMap','NumberTitle','off','Color',[.3 .3 .3]);
%extracts the content of the table as a categorical array. 
% {rownumber,variablenumber}. {100,1} = row 100,variable 1.
%converts the categorical array into a string array.
%joins the string array across the column.
%string(T{100:105,1}); implies from row 100 to row 105 and use variable 1.
%This line simply adds the name of the file at row 100 to the path of the
%file. Hnece we get a full filepath.

filename = strcat('\Users\Ali\Desktop\Documents\DataVis\Projekt\data\day\',string(T{100,1}));


 map100 = getCylinderHeatMap(filename);
 roterOven = createSurfCylinder(map100);

s = uicontrol('Style','Slider','Parent',mainFigure,...
    'Units','normalized','Position',[0 0 1 .025],...
    'Value',1,'Callback',{@slider_callback1},'min','max',1000);

脚本getCylinderHeatMap并不重要,因为它只返回一个带有值的矩阵来创建圆柱体。

汽缸创建脚本。

function cylinder = createSurfCylinder(matrix) 
%Load heat map.
load('myHeatMap.mat','myHeatMap');

%%
%Cylinder creation
Sample_Range = 255 - 0;
Temperature_Range = 450 - 50;

Multiplier = Temperature_Range/Sample_Range;
map100 = matrix.*Multiplier + 50;


%Setting up the figure%
Radius = 1.5;
Number_Of_Data_Points = 360;
theta = linspace(0,2*pi,Number_Of_Data_Points);

%The xy values according to radius and number of points%
Z_Circle = Radius*cos(theta);
Y_Circle = Radius*sin(theta);

map100 = rot90(map100);

Height = 512;
Z_Circle = repmat(Z_Circle,Height,1);
Y_Circle = repmat(Y_Circle,1);
X_Length = (1:512)';
X_Length = repmat(X_Length,Number_Of_Data_Points);

figure('Position',[10 10 800 500])

clf;
close;
%surf(X_Circle,Y_Circle,Z_Height,'Cdata',map100); vertical
%subplot(1,3,1:2); 
cyl = surf(X_Length,Z_Circle,map100); 
title("3D Heatmap Plot");
zlabel("Z-Position");
ylabel("Y-Position");
xlabel("Length(Cm)");
%Reverse Y axis.
set(gca,'Ydir','reverse')
colormap(myHeatMap);
colorbar;
shading interp

Maximum_Value = 450;
Minimum_Value = 50;
caxis([Minimum_Value Maximum_Value]);

%Show the image in the subplot and add custome color coding to it.
% subplot(1,3); imshow(rot90(map100));
% colormap(myHeatMap);
% caxis([Minimum_Value Maximum_Value]);
cylinder = cyl;
%%
end

请多多帮助,因为我已经坚持了2天。

解决方法

带有捕捉点的MATLAB GUI uislider()

使用回调函数绘制随机测试数据时,更改滑块值时将绘制下图。滑块值可在此代码内的回调函数Snap_Slider()中获得,图中的图形和图像可根据需要进行更新。我建议您添加一个uieditfield,以使滑块更精确地选择图像/绘图。可以在希望由用户或其他代码修改的任何元素上调用回调函数。可以根据需要调用回调函数。在这种情况下,值是由附加到元素的.ValueChangedFcn事件指示的更改的,在这种情况下,名为Slider的uislider。可以使用以下形式创建回调:

Slider.ValueChangedFcn = @(Slider,event) Callback_Function();

回调函数中的输入也是可以接受的,并且可以包含其他UI(用户界面)元素。

组件/元素包括:

图→uifigure() (父容器)
情节→uiaxes()
图片→uiimage()
滑块标签→uilabel()
滑块→uislider()

Slider UIFigure

clf;
clear;
close all;
clc;

%Figure/parent container (uifigure) properties%
App = uifigure('Scrollable','on','Name','Heatmap Plots','NumberTitle','off');
App_Width = 1000; App_Height = 500;
App.Position = [0 0 App_Width App_Height];

%Slider label (uilabel) properties%
Slider_Label = uilabel('Parent',App);
Slider_Label.Text = "Cylinder Number";
Slider_Label.Position = [25 20 200 100];

%Slider (uislider) properties%
Slider = uislider('Parent',App);
Slider.Limits = [1 1000];
Slider.Value = 1;
Slider_Width = App_Width - 50;
Margin = (App_Width - Slider_Width)/2;
Slider.Position = [Margin 50 Slider_Width 3];
Slider.MajorTicks = (1:100:1000);
Slider.FontSize = 6;
Red = 87; Green = 207; Blue = 220;
Slider.FontColor = [Red/255 Green/255 Blue/255];

%Plot (uiaxes) properties%
Heatmap_Cylinder_Plot = uiaxes('Parent',App);
Heatmap_Cylinder_Plot_X_Position = 100;
Heatmap_Cylinder_Plot_Y_Position = 100;
Heatmap_Cylinder_Plot_Height = 350;
Heatmap_Cylinder_Plot_Width = 400;
Heatmap_Cylinder_Plot.Position = [Heatmap_Cylinder_Plot_X_Position Heatmap_Cylinder_Plot_Y_Position Heatmap_Cylinder_Plot_Width Heatmap_Cylinder_Plot_Height];
Heatmap_Cylinder_Plot.GridColor = [0.15 0.15 0.15];
Heatmap_Cylinder_Plot.XGrid = 'on';
Heatmap_Cylinder_Plot.YGrid = 'on';
Heatmap_Cylinder_Plot.ZGrid = 'on';

%Image (uiimage) properties%
Heatmap_Image = uiimage('Parent',App);
Heatmap_X_Position = (App_Width/2) + 50;
Heatmap_Y_Position = 80;
Heatmap_Height = 350;
Heatmap_Width = 400;
Heatmap_Image.Position = [Heatmap_X_Position Heatmap_Y_Position Heatmap_Height Heatmap_Width];

%Callback function as the slider is moved%
Slider.ValueChangedFcn = @(Slider,event) Snap_Slider(Slider,Slider_Label,Heatmap_Cylinder_Plot,Heatmap_Image);


%Callback function definition%
function [] = Snap_Slider(Slider,Heatmap_Image)
Slider_Value = Slider.Value;
Slider.Value = round(Slider.Value);

Slider_Label.Text = "Cylinder Number: " + num2str(Slider.Value);

fprintf("Plotting figure %d\n",Slider.Value);
%Put plotting code here%
plot(Heatmap_Cylinder_Plot,[1 2 3 4 5 6 7]);

%Put image plotting code here%
Heatmap_Image.ImageSource = 'peppers.png';




end

使用MATLAB R2019b运行

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res