Plot in AppDesigner with durations

Hey;
I'm currently designing a App in AppDesigner. In this App you can Plot Data over Time. I tried to figure out how to plot durations in normal Matlab. Below is my Code. This code worked fine in normal Matlab for me. But I couldn't figure out how to convert this into App Designer. It gives me the error that xlim and xtick must be numeric values and no duration values. Is it possible to plot in AppDesigner via durations and how the Plot Setting need to be written?
clc;
%Read mat-file
files = dir('examplefolder/*.mat*');
m = matfile(string(files.folder)+'/'+string(files.name));
% Variables
t = m.Data_time_L1_rms;
P_L1 = m.Data_P_L1;
%Convert time variable into duration
sec = seconds(t);
mins = minutes(sec);
%Plot
p = plot(sec,P_L1);
%Settings
xlim([sec(1) sec(end)+0.05*sec(end)]);
xticks([0:seconds(30):minutes(mins(end))]);
xtickformat('m');

4 Commenti

Can you share your mat file? Use the paperclip icon to attach it to your post.
I attached my current App to the post
Thank you. Could you also attach a sample data set? One of your mat files.
the problem is that the all data sets i have are to large to attach atleast 1GB or more a matfile

Accedi per commentare.

Risposte (1)

Cris LaPierre
Cris LaPierre il 12 Nov 2020
Modificato: Cris LaPierre il 12 Nov 2020
There is no difference in app designer between plotting numbers and plotting durations. You just plot it. The one thing to make sure you do is specify the target axes for all your plotting and setting commands. Here's code from a simplified app where the plotting command is placed in the callback function of a pushbutton.
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: PlotButton
function PlotButtonPushed(app, event)
% Variables
t = 1:100;
P_L1 = sin(0.15*t);
%Convert time variable into duration
sec = seconds(t);
mins = minutes(sec);
%Plot
plot(app.UIAxes,sec,P_L1);
%Settings
xlim(app.UIAxes,[sec(1) sec(end)+0.05*sec(end)]);
xticks(app.UIAxes,[0:seconds(30):minutes(mins(end))]);
xtickformat(app.UIAxes,'m');
end
end

8 Commenti

Robin Herman
Robin Herman il 12 Nov 2020
Modificato: Robin Herman il 12 Nov 2020
Thanks for the help so far!
But I get this error when im using your exact code in my App.
Error using xlim (line 31)
Limits must be a 2-element vector of increasing numeric values.
Cris LaPierre
Cris LaPierre il 12 Nov 2020
Modificato: Cris LaPierre il 12 Nov 2020
I can duplicate that error, but only if I don't specify app.UIAxes in the xlim command.
...
%Plot
plot(app.UIAxes,sec,P_L1);
%Settings
xlim([sec(1) sec(end)+0.05*sec(end)]);
xticks(app.UIAxes,[0:seconds(30):minutes(mins(end))]);
xtickformat(app.UIAxes,'m');
I modified the app you shared previously by adding a plot button in the top left, and the exact code I shared above in the button callback function. It appears to work.
I've attached you app with my update.
I opened your modified app and and runned it. it worked for me, i open my app, with the exact same code, gives me this error attached in the picture. I dont get it...
Cris LaPierre
Cris LaPierre il 12 Nov 2020
Modificato: Cris LaPierre il 12 Nov 2020
So the code is not exactly the same. My thought would be to check that Ieff_max_L123 and Ieff_min_L123 are scalars (1x1). My suspicion is that they are not.
EDIT: Ah, spotted something.
It looks like you forgot your closing parentheses. It likely should end "...3))]);"
Robin Herman
Robin Herman il 12 Nov 2020
Modificato: Robin Herman il 12 Nov 2020
Checked it, these Values are both scalars, i have the feeling that there must be somewhere else an error in the code that causes this current error
Edit: Spotted that error aswell, fixed it but didnt changed anything
Afterwards I solved the initial Problem
I tried to plot before the if loop begins and than it accepted my coding
Cris LaPierre
Cris LaPierre il 12 Nov 2020
Modificato: Cris LaPierre il 12 Nov 2020
You should have gotten a different error about unbalanced parentheses.
I agree - there appears to be something in your app. The code you are wanting to implement obviously works fine on its own. Any chance you can create a sample data set for testing?
As an alternative, could you clear your Workspace, then load the *.mat file into MATLAB. In the Command Window, type whos and paste the result here.
solved the problem ! I edited my answer
thanks anyways putting so much effort into my request!

Accedi per commentare.

Categorie

Scopri di più su Develop Apps Using App Designer in Centro assistenza e File Exchange

Prodotti

Release

R2020b

Richiesto:

il 11 Nov 2020

Commentato:

il 12 Nov 2020

Community Treasure Hunt

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

Start Hunting!

Translated by