Plot in AppDesigner with durations
Mostra commenti meno recenti
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
Cris LaPierre
il 11 Nov 2020
Can you share your mat file? Use the paperclip icon to attach it to your post.
Robin Herman
il 11 Nov 2020
Cris LaPierre
il 11 Nov 2020
Thank you. Could you also attach a sample data set? One of your mat files.
Robin Herman
il 12 Nov 2020
Risposte (1)
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
il 12 Nov 2020
Modificato: Robin Herman
il 12 Nov 2020
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.
Robin Herman
il 12 Nov 2020
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
il 12 Nov 2020
Modificato: Robin Herman
il 12 Nov 2020
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?
Cris LaPierre
il 12 Nov 2020
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.
Robin Herman
il 12 Nov 2020
Categorie
Scopri di più su Develop Apps Using App Designer in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!