How to to create a dynamic scatter2 or scatter3 plot?
6 次查看(过去 30 天)
显示 更早的评论
Hi! :)
I havent tried it yet because I am a little confused about how to do this in matlab app designer (2018): I want to create a scatter 2 plot , if it is going to be 2 dimensional then I want the values to change with a third value that is obtained from a value changing callback of a knob. I dont think I can have a scatter 3 plot as the value that is changed (from the knob) is just a value and not an array. The other two column (x, y) are supposed to be two columns from a table.
Thanks
0 个评论
回答(1 个)
Austin M. Weber
2024-2-11
编辑:Austin M. Weber
2024-2-11
Assuming I understand your question correctly, you can follow these steps:
1. Right-click the Knob object in your app, go to Callbacks >> Add ValueChangingFcn callback
2. Define your callback function:
% Create example data table
rng(1)
x = linspace(0,6*pi,100)';
y = sin(x);
T = array2table([x,y],'VariableNames',{'X','Y'});
% Get the changing knob value
changingValue = event.Value;
% Update scatter plot
scatter(app.UIAxes, T.X, T.Y .* changingValue)
3. Save your app and then run the app to see if it works.
When you turn the knob in the app the UIAxes should automatically update.
You can set the values on the knob to whatever you like in the Design View window when you make your app. You can also program the chaning value on the knob to affect the data in your table however you like. In the example above, I multiply the values in the table variable Y by the changing value on the knob.
3 个评论
Austin M. Weber
2024-2-11
So, you want the scatter plot to only show one point at a time? In that case, you can try the following in your knob callback function:
% Load the osmotic_data table (must be on your current MATLAB path)
T = readtable('osmotic_data.csv');
% Adjust the knob limits to the minimum and maximum value of weight percent
app.Knob.Limits = [min(T.weight_percent_best_salt_1) max(T.weight_percent_best_salt_1)];
app.Knob.MajorTicks = min(T.weight_percent_best_salt_1) : max(T.weight_percent_best_salt_1);
% Get the value on the knob
changingValue = round(event.Value);
% Get the index position of the knob value in your weight percent data
idx = find(changingValue == T.weight_percent_best_salt_1);
% Plot the corresponding point for activity and osmotic pressure
scatter(app.UIAxes,T{idx,1},T{idx,2},50,'red','filled','o')
ylabel(app.UIAxes,'Osmotic Pressure')
xlabel(app.UIAxes,'Activity')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!