Export the data into an excel different coloumns and also add the image into the excel file in a different sheet of the input sheet.
1 回表示 (過去 30 日間)
古いコメントを表示
I am selecting an excel file for input and storing the name.
properties (Access = private)
RPS = 2*pi/60;
EM_Max_Spd_F;
EM_Base_Spd_F;
EM_Max_Trq_Cont_F;
file;
EM_Spd_F;
EM_Trq_Cont_F;
EM_Pwr_Cont_F;
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
[app.file,filepath]= uigetfile('*.xlsx');
if isequal(app.file,0)
msgbox('Please Input an Excel File')
else
filename = fullfile(filepath,app.file);
t= readcell(filename,'Sheet','Input','Range','H2:H8');
end
tmat = cell2mat(t);
app.EM_Max_Trq_Cont_FNmEditField.Value = tmat(1);
app.EM_Base_Spd_FRPMEditField.Value =tmat(2);
app.EM_Max_Spd_FRPMEditField.Value =tmat(3);
app.EM_Max_Trq_Cont_RNmEditField.Value= tmat(5);
app.EM_Base_Spd_RRPMEditField.Value = tmat(6);
app.EM_Max_Spd_RRPMEditField.Value = tmat(7);
app.FileNameEditField.Value = app.file;
app.EM_Max_Trq_Cont_F = app.EM_Max_Trq_Cont_FNmEditField.Value;
app.EM_Base_Spd_F = app.EM_Base_Spd_FRPMEditField.Value ;
app.EM_Max_Spd_F = app.EM_Max_Spd_FRPMEditField.Value;
end
% Button pushed function: PlotButton
function PlotButtonPushed(app, event)
app.EM_Spd_F = 0:500:app.EM_Max_Spd_F;
app.EM_Trq_Cont_F = zeros(1,length(app.EM_Spd_F));
app.EM_Pwr_Cont_F =zeros(1,length(app.EM_Spd_F));
EM_Max_Pwr_Cont_F = (app.EM_Base_Spd_F*app.RPS*app.EM_Max_Trq_Cont_F)/1000;
for i= 1:length(app.EM_Spd_F)
if app.EM_Spd_F(i) <=(app.EM_Base_Spd_F)
app.EM_Trq_Cont_F(i) = app.EM_Max_Trq_Cont_F;
app.EM_Pwr_Cont_F(i) = app.EM_Trq_Cont_F(i)*app.EM_Spd_F(i)*app.RPS/1000;
else
app.EM_Trq_Cont_F(i)= EM_Max_Pwr_Cont_F*1000/(app.EM_Spd_F(i)*app.RPS);
app.EM_Pwr_Cont_F(i) = EM_Max_Pwr_Cont_F;
end
end
plot(app.UIAxes,app.EM_Spd_F,app.EM_Trq_Cont_F,"DisplayName","Front Motor Torque","LineWidth",3);
yyaxis (app.UIAxes ,'left')
text(app.UIAxes,app.EM_Base_Spd_F,app.EM_Max_Trq_Cont_F,'Base Speed','Color','red','FontSize',8);
val = app.EM_Trq_Cont_F;
last_ele =val(end);
text(app.UIAxes,app.EM_Max_Spd_F,last_ele,'No Load Speed','Color','red','Fontsize',8);
grid on
xlabel (app.UIAxes,"Motor Speed (RPM)");
ylabel (app.UIAxes,"Motor Torque (Nm)");
yyaxis (app.UIAxes ,'right')
plot(app.UIAxes,app.EM_Spd_F,app.EM_Pwr_Cont_F,"DisplayName","Front Motor Power");
ylabel (app.UIAxes,"Motor Power (Nm)")
legend;
end
I want to export the data for the Motor speed , Motor Torque and Motor power into the different sheet of the input sheet i loaded but i am able to get the data in excel but its all in one single line i want it to be in a table format.
% Button pushed function: ExportButton
function ExportButtonPushed(app, event)
t= table{(app.EM_Spd_F,app.EM_Trq_Cont_F,app.EM_Pwr_Cont_F)};
app.UITable.Data = t;
writetable(app.UITable.Data,'output.xlsx','WriteRownames',t
1 件のコメント
chicken vector
2023 年 5 月 5 日
Unrequested tip: the community is less inclined to help you if you didn't accept answers on your previous questions.
回答 (1 件)
Divyanshu
2023 年 5 月 19 日
Hi Santhosh,
I have taken some sample data for three variables of app ‘speed’, ‘power’ and ‘torque’ all with same size. And in the callback attached to export button of app I have created a table using these three vectors.
Here is the code snippet for same:
methods (Access = private)
% Code that executes after component creation
function loadData(app)
app.speed = [2 3 4 5 6 7]';
app.torque = [1 4 5 2 8 9]';
app.power = [10 20 11 23 34 45]';
end
% Button pushed function: Button
function exportFunc(app, event)
t = table(app.speed,app.power,app.torque,'VariableNames',["speed" "power" "torque"]);
writetable(t,"output.xlsx",'WriteVariableNames',true);
end
end
Feel free to modify the values of various properties of both ‘table’ & ‘writetable’ function according to your use case. Please refer the following documentation for more information:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!