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 件のコメント

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

サインインしてコメントする。

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 11 月 12 日
編集済み: Cris LaPierre 2020 年 11 月 12 日

0 投票

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 件のコメント

Robin Herman
Robin Herman 2020 年 11 月 12 日
編集済み: Robin Herman 2020 年 11 月 12 日
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 2020 年 11 月 12 日
編集済み: Cris LaPierre 2020 年 11 月 12 日
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
Robin Herman 2020 年 11 月 12 日
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 2020 年 11 月 12 日
編集済み: Cris LaPierre 2020 年 11 月 12 日
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 2020 年 11 月 12 日
編集済み: Robin Herman 2020 年 11 月 12 日
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 2020 年 11 月 12 日
編集済み: Cris LaPierre 2020 年 11 月 12 日
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
Cris LaPierre 2020 年 11 月 12 日
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
Robin Herman 2020 年 11 月 12 日
solved the problem ! I edited my answer
thanks anyways putting so much effort into my request!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

リリース

R2020b

タグ

質問済み:

2020 年 11 月 11 日

コメント済み:

2020 年 11 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by