1

I got 2 functions in my matlab script. These functions exchange the data via a *.mat file. In one of the functions, I read the number of specific files and a data from them. Later I process and store the variable ggd in proj1.mat file. As shown below :

    function browse_pushBtn_Callback(hObject, eventdata, handles)
% hObject    handle to browse_pushBtn (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.directory = uigetdir('C:\temp\');
guidata(hObject,handles);
ggd.directory = handles.directory;
if (ggd.directory)
    set(handles.browse_textEdit,'String',handles.directory);
    disp2listbox(handles.mainLog_listBox, '1. Searching for GGD Datafile:');
    ggd = MyRead(ggd);
    disp2listbox(handles.mainLog_listBox, sprintf('     -%d Bilder 
    gefunden',length(ggd.bilds)));
    save proj1 ggd;
else
    set(handles.browse_textEdit,'String','Select a directory');
end

The Second function is :

function start_pushBtn_Callback(hObject, eventdata, handles)
% hObject    handle to start_pushBtn (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

option = get(handles.mainMenu,'Value');
if (option == 1)
    disp2listbox(handles.mainLog_listBox, '2. Calculating the quadratic size..');
    fprintf('path is : %s\n', pwd); % did just to check the path (for debugging purpose)
    load proj1 ggd;
    ggd = MyProcess(ggd); 
    save proj1 ggd;
    disp2listbox(handles.mainLog_listBox, sprintf('     -MySize: %d X %d',ggd.X(1), ggd.Y(2)));
    disp2listbox(handles.mainLog_listBox, '3. opening another function...');
    % call to another function 
elseif (option == 2)
    disp2listbox(handles.mainLog_listBox, '2. opening third function...');
    % call to third different function
end

The funny thing is that these two functions work perfectly fine when I run them in Matlab tool. Later, I compile the standalone executable for my application. This standalone application works fine until the first function; but, when I call the second function, it loads the proj1.mat file from another unknown location that contains totally different data.
Have no idea what is the problem that causing such weird behaviour.

I checked the current paths (pwd) in second function while executing standalone and found it to be the same as the one in first function.

Any ideas ??

Vahe Tshitoyan
  • 1,439
  • 1
  • 11
  • 21
adi
  • 39
  • 7
  • It is possible the second function included an existing mat file when you compiled it. Try deleting that file when you are compiling. – Navan Jun 08 '17 at 16:54
  • You might find [this](http://blogs.mathworks.com/loren/2008/08/11/path-management-in-deployed-applications/) useful – Vahe Tshitoyan Jun 08 '17 at 21:43
  • @Navan I also thought of the same possibiliy but can you please guide me how can I delete **'that *.mat '** while compiling - thanks – adi Jun 09 '17 at 08:11
  • You cannot do it while compiling. You need to do that before compiling. – Navan Jun 09 '17 at 14:04

1 Answers1

1

If you need to keep writing and reading from a file in a deployed application, I would recommend creating a local directory in user's machine's App Data and storing all the files there. You can do this by using the following function from matlab central. E.g. something like

file_root = getapplicationdatadir('your.application.name',1,1);

should create a directory (if it does not exist) on the user's computer where it will store all the files, and variable root will give you the absolute path to that directory. You can then use it to save and load the files. E.g.

save([file_root '/proj1.mat'],'ggd');

in the first function, and

load([file_root '/proj1.mat'],'ggd');

in the second function. This way you know exactly where the file is stored. Also, read the link I mentioned earlier in the comment.

Vahe Tshitoyan
  • 1,439
  • 1
  • 11
  • 21
  • thanks I tried this already.. but was still curious to know the reason.. thank you again – adi Jun 09 '17 at 08:48