How to fix "unrecognized table variable name" error?
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have the following code for App Designer which it does exactly what I want.
The code upload a file and then the user has to select the starting date to plot the data on Axes but also the user has to select the ending date. This is done by using "date picker" See the image for the result.
When ever the user change the date of the Start or Ending then the timestamp change on the Axes.
To do that I have to write my code under functions of 'date picker start' and 'date picker ending'. Again the code is working fine but I think I am overwriting it in two different locations.
I want to minimize my code as much as possible because I am just trying to see how it works here. And then I have a different GUI that has many Axes and files to upload.
Here is the main code : And I also uploaded the files that I am working with.
classdef Gui_app < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UIAxes matlab.ui.control.UIAxes
UPLOADButton matlab.ui.control.Button
StartDatePickerLabel matlab.ui.control.Label
StartDatePicker matlab.ui.control.DatePicker
EndingDatePickerLabel matlab.ui.control.Label
EndingDatePicker matlab.ui.control.DatePicker
end
properties (Access = private)
IN1, IN2, tr, tt, value1, value2, data; % Description
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: UPLOADButton
function UPLOADButtonPushed(app, event)
app.data=readtable('EKW.csv','ReadVariableNames', true);
end
% Value changed function: StartDatePicker
function StartDatePickerValueChanged(app, event)
app.value1 = app.EndingDatePicker.Value;
app.IN1=datestr(app.value1);
app.value2 = app.StartDatePicker.Value;
app.IN2=datestr(app.value2);
Time_Stamp=datetime(app.data.Timestamp,'InputFormat','yyyy-MM-dd''T''HH');
app.tt = timetable(Time_Stamp,app.data.YYY);
app.tr = timerange(app.IN2,app.IN1);
daterange = app.tt(app.tr,:);
plot(app.UIAxes,daterange.Time_Stamp,daterange.Var1)
end
% Value changed function: EndingDatePicker
function EndingDatePickerValueChanged(app, event) % I was trying to write everything under this function but then the ....
% graph will not continously once the user change the date of StartDatePicker
app.value1 = app.StartDatePicker.Value;
app.IN1=datestr(app.value1);
app.value2 = app.EndingDatePicker.Value;
app.IN2=datestr(app.value2);
Time_Stamp=datetime(app.data.Timestamp,'InputFormat','yyyy-MM-dd''T''HH'); % Also, I want to write this only on one location ..
% so I do not have to read the file everytime that I want to use Time_Stamp
% I tried to make 'Time_Stamp' as a properties but it give me the following error on 'Plot function'
app.tt = timetable(Time_Stamp,app.data.YYY);
app.tr = timerange(app.IN1,app.IN2);
daterange = app.tt(app.tr,:);
plot(app.UIAxes,daterange.Time_Stamp,daterange.Var1) % unrecognized table variable name Time_Stamp
% I did use app.Time_Stamp but still not working
end
end
0 commentaires
Réponses (1)
Srijith Kasaragod
le 7 Avr 2022
Modifié(e) : Srijith Kasaragod
le 7 Avr 2022
You can assign a single 'ValueChangedFcn' callback for both the date pickers to remove redundant code from your app. Refer the attached app to see how this can be achieved.
Regards,
Srijith.
0 commentaires
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!