How can i run the same scripts of Matlab in Matlab app design?
1 view (last 30 days)
Show older comments
Line 1: t=readtable("Load.xlsx");
Line 2: app.UITable.Data=t;
Line 3: time=t(:,1); % first colomn
Line 4: power_PV=t(:,2); % second colomn
Line 5: peak_power=max(power_PV);
Line 6: average_power=sum(power_PV)/length(power_PV);
Line 7: app.PeakPowerEditField.Data=peak_power;
Line 8: app.AveragePowerEditField.Data=average_power;
This script i have executed in Matlab already. But unable to run this script in Matlab App Design.
showing error in line 5: "Invalid data type. First argument must be numeric or logical"
i think it will be shown the same issue with "sum" function.
would you please light up what is the reason and the solution ? attached the excel file.
0 Comments
Accepted Answer
Cris LaPierre
on 5 Nov 2021
You get the same error if you run your script in MATLAB (after commenting out the lines starting with app.). The issue is that t is a table. When you use paretheses on a table, the output is a table (time, power_Pv). The functions max and sum do not accept tables as inputs. The solution is to either use curly braces (returns an array)
time=t{:,1}; % first colomn
power_PV=t{:,2}; % second colomn
or dot notation
time=t.Time; % first colomn
power_PV=t.LoadPower; % second colomn
Personally, I would use dot notation without extracting the values to a separate variable.
t=readtable("Load.xlsx");
app.UITable.Data=t;
app.PeakPowerEditField.Data = max(t.LoadPower);
app.AveragePowerEditField.Data = sum(t.LoadPower)/length(t.LoadPower);
2 Comments
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!