matlab slider max,MATLAB - adding calibrated slider to figure

2023-10-23 12:30

本文主要是介绍matlab slider max,MATLAB - adding calibrated slider to figure,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原文:

I am trying to add a calibrated slider to this figure.

its a figure frame with a 3d surf plot in it.

x2BKO.jpg

Now as you can see I managed to create a slider with the "uicontrol" command but i can not calibrate it nor created any ticks on it.

I tried using the "uislider" which creates a beautiful slider just like the one I want but for some reason I cant cant add one of those in a figure (only works if I use uifigure to create the original figure however when I do this I cant plot my surf plot in it and I don't know why).

This is my code.

Main script.

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', 1, 'max', 1000);

the script getCylinderHeatMap is not of any importance as it only returns a matrix with values to create the cylinder.

Cylinder creation script.

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,Height,1);

X_Length = (1:512)';

X_Length = repmat(X_Length,1,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,Y_Circle,Z_Circle,'Cdata',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,3); imshow(rot90(map100));

% colormap(myHeatMap);

% caxis([Minimum_Value Maximum_Value]);

cylinder = cyl;

%%

end

Please any help would be much appreciated as I have been stuck on this for 2 days now.

# Answer 1

4d350fd91e33782268f371d7edaa8a76.png

MATLAB GUI uislider() with Snapping Points

With random test data plotted using the callback function, the following figure is plotted when the slider value is changed. The slider value can be obtained within the callback function Snap_Slider() within in this code the plots and images in the figure can be updated as pleased. I'd suggest adding a uieditfield for more precise image/plot selection in addition to the slider. A callback function can be called on any element that expects to be modified by the user or other code. A callback function can be called depending on the case required. In this case, it is when the value is changed indicated by .ValueChangedFcn event attached to the element in this case the uislider named Slider. A callback can be created in the form:

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

Inputs in the callback function are also acceptable and can include other UI (User Interface) elements.

Components/Elements Include:

Figure → uifigure() (parent container)

Plot → uiaxes()

Image → uiimage()

Slider Label → uilabel()

Slider → uislider()

1e3f58dd8e1348a15dabe93eb5fcb644.png

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,Slider_Label,Heatmap_Cylinder_Plot,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

Ran using MATLAB R2019b

这篇关于matlab slider max,MATLAB - adding calibrated slider to figure的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/267832

相关文章

matlab读取NC文件(含group)

matlab读取NC文件(含group): NC文件数据结构: 代码: % 打开 NetCDF 文件filename = 'your_file.nc'; % 替换为你的文件名% 使用 netcdf.open 函数打开文件ncid = netcdf.open(filename, 'NC_NOWRITE');% 查看文件中的组% 假设我们想读取名为 "group1" 的组groupName

利用matlab bar函数绘制较为复杂的柱状图,并在图中进行适当标注

示例代码和结果如下:小疑问:如何自动选择合适的坐标位置对柱状图的数值大小进行标注?😂 clear; close all;x = 1:3;aa=[28.6321521955954 26.2453660695847 21.69102348512086.93747104431360 6.25442246899816 3.342835958564245.51365061796319 4.87

C# double[] 和Matlab数组MWArray[]转换

C# double[] 转换成MWArray[], 直接赋值就行             MWNumericArray[] ma = new MWNumericArray[4];             double[] dT = new double[] { 0 };             double[] dT1 = new double[] { 0,2 };

libsvm在matlab中的使用方法

原文地址:libsvm在matlab中的使用方法 作者: lwenqu_8lbsk 前段时间,gyp326曾在论坛里问libsvm如何在matlab中使用,我还奇怪,认为libsvm是C的程序,应该不能。没想到今天又有人问道,难道matlab真的能运行libsvm。我到官方网站看了下,原来,真的提供了matlab的使用接口。 接口下载在: http://www.csie.ntu.edu.

Matlab/Simulink中PMSM模型的反电动势系数和转矩系数

Matlab/Simulink中PMSM模型的反电动势系数和转矩系数_matlab pmsm-CSDN博客

MATLAB层次聚类分析法

转自:http://blog.163.com/lxg_1123@126/blog/static/74841406201022774051963/ 层次聚类是基于距离的聚类方法,MATLAB中通过pdist、linkage、dendrogram、cluster等函数来完成。层次聚类的过程可以分这么几步: (1) 确定对象(实际上就是数据集中的每个数据点)之间的相似性,实际上就是定义一个表征

file-max与ulimit的关系与差别

http://zhangxugg-163-com.iteye.com/blog/1108402 http://ilikedo.iteye.com/blog/1554822

MATLAB的fix(),floor()和ceil()函数的区别与联系

fix(x),floor(x)和ceil(x)函数都是对x取整,只不过取整方向不同而已。 这里的方向是以x轴作为横坐标来看的,向右就是朝着正轴方向,向左就是朝着负轴方向。 fix(x):向0取整(也可以理解为向中间取整) floor(x):向左取整 ceil(x):向右取整 举例: 4个数:a=3.3、b=3.7、c=-3.3、d=-3.7 fix(a)=3 fl

MATLAB中的eig函数

在MATLAB中,计算矩阵A的特征值和特征向量的函数是eig(A),常用的调用格式有5种: E=eig(A):求矩阵A的全部特征值,构成向量E。 [V,D]=eig(A):求矩阵A的全部特征值,构成对角阵D,并求A的特征向量构成V的列向量。 [V,D]=eig(A,'nobalance'):与第2种格式类似,但第2种格式中先对A作相似变换后求矩阵A的特征值和特征向量,而格式3直接求矩阵A的特

MATLAB中的diag函数

diag函数功能:矩阵对角元素的提取和创建对角阵 设以下X为方阵,v为向量 1、X = diag(v,k)当v是一个含有n个元素的向量时,返回一个n+abs(k)阶方阵X,向量v在矩阵X中的第k个对角线上,k=0表示主对角线,k>0表示在主对角线上方,k<0表示在主对角线下方。例1: v=[1 2 3]; diag(v, 3) ans =      0     0     0