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 件のコメント
Cris LaPierre
2020 年 11 月 11 日
Can you share your mat file? Use the paperclip icon to attach it to your post.
Robin Herman
2020 年 11 月 11 日
Cris LaPierre
2020 年 11 月 11 日
Thank you. Could you also attach a sample data set? One of your mat files.
Robin Herman
2020 年 11 月 12 日
回答 (1 件)
Cris LaPierre
2020 年 11 月 12 日
編集済み: Cris LaPierre
2020 年 11 月 12 日
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
2020 年 11 月 12 日
編集済み: Robin Herman
2020 年 11 月 12 日
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
2020 年 11 月 12 日
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
2020 年 11 月 12 日
編集済み: Robin Herman
2020 年 11 月 12 日
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
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
2020 年 11 月 12 日
カテゴリ
ヘルプ センター および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!