CD statment and connection from matlab to C# ?
Show older comments
i have created matlab file (function) which contains save statment i have to save image histogram value(Hist)
folder_name= 'query' ;
addpath(folder_name);
file_name = [folder_name 'image(1)'];
save(file_name,'Hist');
this runs perfectly using matlab with no problem the problem occurs when i run the code using C# after converting the matlab file to .dll file it cannot addpath to folder_name or find it although i have added the folder to the package of deployment tool
6 Comments
Image Analyst
on 23 May 2015
What does "folder_name('query');" do? folder_name appears to be a function name, yet you're passing it to addpath, which would not make sense unless it returned something in the event you did not pass any arguments to it. What's going on there? And what is Hist? I presume it's a double or integer array. Also, you're better off using
file_name = fullfile(foldername 'image(1)');
Rather than the way you did it. But I'm not sure what foldername is . I know it's different than folder_name because it does not have an underline in it, but, like Hist, I guess it must come from prior code that you did not show us. All in all, this code is a mystery to me.
Walter Roberson
on 23 May 2015
What is folder_name('query') ? And what is foldername ? Why are you wanting to add it to the path? And why are you not using fullfile() instead of manually concatenating the parts for the file_name ?
sara selim
on 24 May 2015
sara selim
on 24 May 2015
sara selim
on 24 May 2015
Jan
on 24 May 2015
I do not understand your comment. Please prefer short sentences to allow non-native speakers to follow.
Answers (2)
Walter Roberson
on 24 May 2015
2 votes
When you use MATLAB Compiler to generate code, the code is not executed in the directory that it was originally compiled in, and the code is not executed in the directory that the user is in when they invoke the executable by name from a command window, and the code is not executed in the home directory of the user who clicked on an icon to launch the executable.
When you use MATLAB Compiler to generate code, then at run-time a temporary directory is created and the components are extracted into the directory, and the code is run from that directory. The root of that directory can be found using the function ctfroot(). Unfortunately I cannot look at the documentation for ctfroot. See http://www.mathworks.com/matlabcentral/answers/59148-for-stand-alone-exe-how-do-i-include-a-folder-of-files-and-know-how-to-access-them
4 Comments
sara selim
on 25 May 2015
Walter Roberson
on 25 May 2015
Use ctfroot and fullfile
folder_name= 'query';
if isdeployed
folder_in_archive = fullfile(ctfroot, folder_name);
else
%assume the current directory is in the right place
folder_in_archive = fullfile(pwd, folder_name);
end
file_name = fullfile(folder_in_archive, 'image(1)');
save(file_name, 'Hist');
sara selim
on 25 May 2015
Walter Roberson
on 25 May 2015
Please mark the Answer as accepted.
Jan
on 24 May 2015
0 votes
Beside the confusing usage of "folder_name" and "foldername" as functions or variables, there is no need to call addpath(folder_name) . Simply omit this line, when the rest is working as wanted.
1 Comment
sara selim
on 24 May 2015
Categories
Find more on Startup and Shutdown 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!