How to to create a dynamic scatter2 or scatter3 plot?

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

Answers (1)

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 Comments

@Austin M Weber Sorry I think I was not clear in my way of explaining the problem: I have a table osmotic data and I want the column weight_percent_best_salt_1 to represent this changing knob value .
Then I have my x value column which are computed values called activity and my y column from the table is called osmotic_pressure. And to each weight_percent_best_salt_1 value I have a value for activity and a value for osmotic pressure and my goal is to to extract that y value and x value that correspond to each changing knob (weight_percent_best_salt_1) value.
I have now explained it in a bettter way I think, :)
Hope you can help me further with my problem
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')

Sign in to comment.

Categories

Asked:

on 11 Feb 2024

Commented:

on 11 Feb 2024

Community Treasure Hunt

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

Start Hunting!