How to to create a dynamic scatter2 or scatter3 plot?

12 visualizaciones (últimos 30 días)
Muazma Ali
Muazma Ali el 11 de Feb. de 2024
Comentada: Muazma Ali el 11 de Feb. de 2024
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

Respuestas (1)

Austin M. Weber
Austin M. Weber el 11 de Feb. de 2024
Editada: Austin M. Weber el 11 de Feb. de 2024
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 comentarios
Austin M. Weber
Austin M. Weber el 11 de Feb. de 2024
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')

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by