Why does my complied MATLAB .exe give me the same output every time I run the standalone application?

1 次查看(过去 30 天)
Why does my complied MATLAB .exe give me the same output every time I run the standalone application?
The program takes in some excel data from an excel file, we do some math, then we output data back to the excel file and open it up for the user to see the output.
This program works perfect in the IDE and the output updates when I change data inside the excel file used as input, but when I make an .EXE and try the program that way, whatever the last data I had in the excel run in the IDE, is ALWAYS the output for the .exe now. Even when I change the data in the excel file and rerun.
How would I go about making this dynamic? Or have the program read in the new data from the excel file with each subsequent run?
example:
******************************************************************************
% read in some data
[num,txt,raw] = xlsread('excelFile','REPORT');
% do some math
x= 5 * num (1)
%export it back to excel file
xlswrite('excelFile',matrix,'sheet1')
%open the file up for the user
winopen('excelFile')
******************************************************************************
any and all help is greatly appreciated

采纳的回答

dpb
dpb 2023-6-29
移动:dpb 2023-6-29
The location of file being opened isn't same in .exe as in the IDE.
Try adding a file dialog message that displays the current working directory inside the executable to see where it's actually looking for the file or
d=dir('excelFile.xl*');
fn=fullfile(d.folder,d.name)
Or, of course, you could hardcode in a specific folder if it isn't needed to ever change or use the uigetfile control to pick a file.
The use of the base file name without an extension is also problematic; what if the user changes which file format to use and then there could be multiple files which match the name; which xlsread chooses in that case isn't documented; similarly, what xlswrite chooses on output wouldn't necessarily match. You need to be much more precise in handling the file names.
xlsread and xlswrite have been deprecated; it is recommended to use readmatrix for numeric data instead.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by