How to plot a scatter plot from a UI table

I have edited and added values to a UI Table based on the Number of sensors needed . I am Trying to find a method to plot the new values in a scatter plot
properties (Access = private)
sensor_table = gobjects(1,1); %initialize as graphics object
T% Table to be shared between callbacks
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: RunButton
function RunButtonPushed(app, event)
N = app.NoofSensorsEditField.Value;
sensor_number = (1:N).';
x_coordinate = zeros(N,1);
y_coordinate = zeros(N,1);
app.T = table(sensor_number, x_coordinate, y_coordinate);
app.sensor_table = uitable(app.UIFigure, 'Data', app.T);
app.sensor_table.ColumnEditable = true;
end
% Button pushed function: ADDButton
function ADDButtonPushed(app, event)
app.T=app.sensor_table;

답변 (1개)

Ananya Tewari
Ananya Tewari 2021년 8월 2일

0 개 추천

Hi,
I understand you want to plot the table data using the scatter plot. We can leverage the scatter plot doc, here is an example for the same. We can give the UIAxes on which data is to be plotted, alongwith the data coordinates.
scatter(app.UIAxes,sensor_number,[x_coordinates;y_coordinates]);
Feel free to change the input arguments as per your requirement.

댓글 수: 9

I tried it but i am getting this "Unrecognized function or variable 'sensor_number'." as the error. I am trying to utilize a data from another call back and i have intialised properties to acquire the table but i dont know how i can do it for the sensor names
% Button pushed function: ADDButton
function ADDButtonPushed(app, event)
app.T=app.sensor_table;
scatter(app.UIAxes,sensor_number,[x_coordinates;y_coordinates]);
additionnally im not sure if the new values are being saved, those are the codes ive implemented to add the new values to the table
Currently sensor_number is not defined and that is the probable cause for the error. You can define sensor_number as a property in the Code and access it inside the callbacks. Please refer to this link for creating properties in App Designer code.
Hope this helps !
Jeet Shetty
Jeet Shetty 2021년 8월 3일
I have already Made the table "t" as the property and sensor_number is a part of that .. won't it be called when i call the table itself?
You can directly use the sensor_number as app.T.sensor_number, if T is accessible and it contains sensor_number as a column.
Jeet Shetty
Jeet Shetty 2021년 8월 3일
yes , it still shows the same error "
Unrecognized method, property, or field"
app.T = table(sensor_number, x_coordinate, y_coordinate);
that is the Code for table "T"
app.sensor_table = uitable(app.UIFigure, 'Data', app.T);
that is the code to add the data.
Jeet Shetty
Jeet Shetty 2021년 8월 4일
i figured the plotting method as i converted every variable to a property but the method that i used to save the variables was not working . so i used the save function but this is the error that i am getting "Error using save Must be a text scalar."
You have to pass save() a list of character vectors or string scalars, each one representing a variable name to save or an option. The names cannot be qualified in any way. For example,
save('myfile.mat', 'app.UIFigure.Data') %WRONG
uif_data = app.UIFigure.Data; save('Myfile.mat', 'uif_data'); %OK
is it to save the Graph or to save the new values inputted into the UI table. This was the code i used to save and plot the new data
function ADDButtonPushed(app, event)
save('app13.mat',get(app.sensor_table,'Data'))
scatter(app.UIAxes,app.x_coordinate, app.y_coordinate);
i tried the code you suggested, but i got this as an error "Unrecognized method, property, or field 'Data' for class 'matlab.ui.Figure'."

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 7월 26일

댓글:

2021년 8월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by