Why do I get an error with fopen when using matlab's mcc? - matlab

Setup:
Windows 7 Enterprise.
Matlab 7.10.0 (R2010a).
mcc compiler: Microsoft Visual C++ 2008 Express.
What's happening:
My project runs fine when running it through Matlab, but when trying to run the .exe through the command prompt after using mcc to compile, the command prompt generates an error.
The mcc command I issue is:
mcc -m -v STARTUP1.m -o EXE_REDUC
The error I receive in the command prompt is:
??? Error using ==> textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
I have a file called LoadXLS.m that loads and reads a .csv file using:
fid = fopen(file,'r');
temp_data = textscan(fid,...args...);
And then I process temp_data.
The csv file I'm trying to load is called spec.csv. It is located two directories down from where I have STARTUP1.m stored. The location of STARTUP1.m is also the place that the mcc generated files are stored to. I have used the pathtool to "Add with subfolders" this location, but am aware that those locations are not transferred to mbuild when compiling.
What I've Tried:
I have gone in and added print statements to print the value of fid to make sure it is valid. When I run it in Matlab, it has a valid value, however when I run in the command prompt it always returns an invalid value of -1.
I have removed all addpath() calls, I have tried adding the STARTUP1.m directory to the mcc ctf archive using:
mcc -m -v -a 'C:\Users\...path...\STARTUP1.m_location' STARTUP1.m -o EXE_REDUC;
However when I do this, I get a different error when running in the command prompt:
Cannot open CTF archive file
'C:\...path...\AppData\Local\Temp\mathworks_tmp_7532_28296'
or
'C:\...path...\AppData\Local\Temp\mathworks_tmp_7532_28296.zip'
??? Undefined function or variable 'matlabrc'.
To fix this, I've tried adding the pragma
%#function matlabrc
to the top of STARTUP1.m to try and enforce its inclusion, but had no success.
I also copied the spec.csv file to a new directory in the ctfroot and changed
fid = fopen(...)
to:
[tempFile, message] = fopen(fullfile(ctfroot, 'Added Config Files', ad.spec_file));
The message is:
message is: No such file or directory
Objective:
Rearranging file locations is a sufficient workaround while the exectuable only runs on my computer, however the idea is to take this standalone and distribute it to multiple people on many different computers. I would like to be able to have a top folder with a startup file and within this folder, have as many subfolders as the package requires. The startup file should be able to access all subfolders and files within them as necessary.
I read something about the exectuable actually running from a "secret location" on the machine here: http://matlab.wikia.com/wiki/FAQ
I would just like to be able to group one entire folder tree with all its files into a package containing the executable and be able to run it anywhere.
More info:
When I put the spec.csv file in the same directory as STARUTP1.m, it finds it fine using mcc without the -a 'path' option and using the following in the LoadXLS.m file:
[tempFile, message] = fopen(ad.spec_file,'r');
This project contains GUIs, generates PDFs, generates plots, and also creates a zip directory.
Thank you in advance.

Related

Postgresql copy command not finding file

when running:
~/fidelity/releases/20220907033831$ ls -a
.
..
.browserslistrc
221005_users_all.csv
_private
the presence of a file is confirmed.
However, when launching a postgresql command
psql fidelity_development
COPY users (id,migrated_id,[...]) FROM '~/fidelity/releases/20220907033831/221005_users_all.csv' DELIMITER ';' CSV HEADER;
The response is unexpected:
ERROR: could not open file "~/fidelity/releases/20220907033831/221005_users_all.csv" for reading: No such file or directory
What am I missing to determine why postgresql cannot see this file?
note this directory was also simlinked as fidelity/current and the same result was obtained when referring to that directory for the file, whereas bash sees it.
Use \COPY command as this one is client based and handles the local path correctly.
While COPY is server based and this could cause issues finding your file.

How to insert a folder into .tar file in MATLAB by using UNIX commands?

I have many folder like data_1,data_2, data_3 etc, that will be generated during program running. I want to copy these folders into .tar file named full_data.tar in a specified folder.
How can I insert folders named data_1,data_2, data_3 etc into full_data.tar in MATLAB by using UNIX commands?
As #kedarps already proposed I would also use the command line. The matlab command to execute command line arguments is:
status = system(command)
It is documented under this link:
system documentation
So if I take the unixcommand from #kedarps this should work:
system('tar -cvf full_tar.tar data_1 data_2 data_3')
I hope this helps

I am encountering an error while using imwrite

I am new to image processing and what I am trying to do is resize an image and store it in tif format, but command window reports an error saying "you don't have the permission to write"
my code is imwrite(B,'myNewFile.tif');
and after running it shows
Error using imwrite (line 10)
Unable to open file "myNewFile.tif" for writing. You may not have write permission.
Do I have to create a file by the name 'myNewFile' before writing the above code?
As the error message states, you are trying to write the file myNewFile.tif to the current working directory. However, you do not have writing permission in the current working direcoty. This is an OS issue, not a Matlab one.
What you can do is change the current working directory (using cd command) and write the image to a different folder where you do have writing permissions.
Alternatively, you can supply a full path to the image file name, directing it to a folder where you have writing permissions.
imwrite( B, fullfile( '/path/to/where/you/can/write', 'myNewFile.tif' ) );
Here are links to the description of some Matlab commands that might help you:
pwd can be used to check what is your current working directory.
You can use cd to change the current working directory.
fullfile helps you construct file names and paths in a generic way without worrying about OS pecularities.

Difference between calling command line directly or from makefile

I have a confusing problem concerning mingw make and windows command line (Win7):
I have a makefile which shall call a vbs file to convert .vds files to .png files. here is the code of the makefile (without the defined variables, you can see the result in the picture below).
VSD2PNG: $(VISIO_OUTPUT)
#echo *** converting visio files to png files finished
define vsd_rule
$(1): $(call FILTER_FUNCTION,$(basename $(notdir $(1))),$(VISIO_FILES))
$(VSD_SCRIPT) $$< $(VISIO_OUTPUT_DIR)
endef
$(foreach file,$(VISIO_OUTPUT),$(eval $(call vsd_rule,$(file))))
leads to
As you can see, the command should call .\tools\visio\convert(.vbs) with two arguments (input file & output directory). Surprising is that the same command executed in windows command line works fine. I tried some modifications to solve the problem (unsuccessfully):
adding file extension to vbs-script leads to error 193, but I cannot find out, what that means.
calling the script without any arguments should lead to a runtime-error in the script, but that leads to make error -1 again (or with file extension 193).
using absolute path for script
Does anybody know more about the differences between calling a script directly from command line or from makefile, which should usually lead to the command line?

Error while try to rename a file name in matlab

This is my code:
filename_date = strcat('Maayanei_yeshua-IC_',file_date,'.pdf')
filenamepdf = strcat(filename,'.pdf')
rename(['C:\Users\user\Desktop\' filenamepdf],['C:\Users\user\Desktop\' filename_date]);
And i get the error:
<??? Error using ==> movefile The system cannot find the path specified.>
or
<??? Undefined function or method 'rename' for input arguments of type 'char'.>
I checked hundreds of times and the file is there... i don't know why it can't find it, any help ?
Use the command
doc rename
to discover that rename is for working with ftp servers, which you are not doing here. What you want is the command movefile
Use the help window brought up by helpwin to look up all the commands you are using.
Also, from the command prompt try
dir(['C:\Users\user\Desktop\' filenamepdf])
to verify the file you want to move exists.