Cannot create .xlsx file in Octave 3.8.2 - matlab

I have just switched from Matlab to Octave 3.8.2 and spending a lot of hours to rewrite my programs.
The issue I am currently having is related to io pkg's xlswrite function.
In the code I have implemented, my Matlab code would search a directory for an .xlsx file with a given name. If there was such a file, it would change the filename to filename_v2 and write data in it , else it would create it first and then write data in it.
However, Octave doesn't seem to work this way.
Actually, whenever I am trying to create a file using xlswrite function I get the following error:
error: xlsopen.m: file filename.xlsx not found
Any idea how I could go round this problem?
Thank you very much in advance.
Kostas
EDIT: I am using Windows 7 and the exact code is:
if exist('Data Logger.xlsx','file')==0
name='Data Logger.xlsx';
else
found=1;
v=1;
while found==1
v=v+1;
name_cand=strcat('Data Logger_v',num2str(v),'.xlsx');
if exist(name_cand,'file')==0
found=0;
end
end
name=name_cand;
end
xlswrite(name,Header)

Solved: Its seems that Octave does not accept spaces in filenames.
Changed Data Logger.xlsx to Data_Logger.xlsx and everything worked perfectly
Thank you all for your willingness to help.
Cheers, Kostas

Related

Cannot create plots in Jupyter using Octave

I'm attempting to get Octave working in Jupyter and while I can execute basic math, I cannot get plots to work. Regardless of what type of graphics library I try to use, I get an error similar to this:
error: feval: function '__init_gnuplot__' not found
error: called from
graphics_toolkit at line 98 column 5
Here's the code that faileds:
register_graphics_toolkit('gnuplot');
available_graphics_toolkits()
graphics_toolkit("gnuplot");
I did some investigation and my best guess is that it looks like it's looking for a file called __init_gnuplot__.cc, based on the fact I found a file with a similar name but ends with '-tst'. However, that file doesn't exist and grepping the entire file structure under the octave directory doesn't find any instances of the function in the error.
Has Anaconda removed that functionality? Does anyone know where that '__init_gnuplot__' function is supposed to be located? Or, better yet, does anyone know how to resolve this?

NONMEM 7.2 reads Matlab codes while processing structures printed by Matlab to csv

I need somebody familiar with both NONMEM 7.2 and Matlab R2013a to answer my question. I used the code published here: http://www.mathworks.com/matlabcentral/fileexchange/34889-struct2csv to make a datafile (a .csv file) for simulations in NONMEM. When NONMEM tries reading the .csv file, it ends up reading code of the file in Matlab. Why is this happening and what is the solution to this?
Additionally, if somebody has an alternative technique of writing structures to a .csv file, I would appreciate it. I'm sorry I cannot post the code because this is related to a research project in progress.
Regards,
Kumpal

Matlab: error using fprintf

This is a script written by someone else, and I don't understand why it is giving me this error (I don't really know Matlab, but this appears to be a fairly straightforward script, so I'm a bit stumped).
The file starts with
clear all
filein=['Runs/'];
Namein1=['AIC'];
Nameout=['Nash'];
It then does a bunch of calculations to get Nash-Sutcliffe coefficients (not important for this issue) and then tries to write the results to one file:
%Write Nash
%Output file writing
%Write file header
D={'Conbination','Nash with Error','Nash-error','RMSE','RMSE-error',...
'AIC', 'MinNash', 'MaxNash'};
NameOut=[filein,Nameout, '.txt'];
fileID = fopen(NameOut,'w');
for i=1:length(D)-1
fprintf(fileID,'%s\t',D{i});
Then more stuff follows, but this is where I get the error message:
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in Nash_0EV_onlyT (line 169)
fprintf(fileID,'%s\t',D{i});
I don't get what is wrong here? The script specifies the file, and uses fopen...? Isn't it supposed to create the file Nash.txt with the fopen statement (this file currently does not exist in my folder Runs/)? What am I missing? Thanks!
PS I am running Matlab2013a (group license via the university) on a MacBook Pro with OSX 10.8
Try using fclose all before calling this script again. Often when testing, the file handle is never released (an error occurs before the file is closed), causing fopen on the same file to fail.
The better way to do this would be to use a more fail-safe construct:
NameOut = [filein Nameout '.txt'];
fileID = fopen(NameOut,'w');
if fileID > 0
try
for i = 1:length(D)-1
fprintf(fileID,'%s\t',D{i});
end
fclose(fileId);
catch ME
fclose(fileId);
throw(ME);
end
else
error('Error opening file.');
end
I am running Win 10 and matlab 2015a, but it happens in mine too.
finally, I realise that the matlab.exe can't write file in the folder /../bin/
so, change to
Nameout=['C:\Users\yourname\DesktopNash'];
try it, then tell me what' going on.
Okay, so as I said, I don't know Matlab... I hadn't properly specified the path for writing! So it was reading the input but I guess didn't know where to write to. Thanks for the answers, it did help me narrow down the problem!

Extract .mat data without matlab - tried scilab unsuccessfully

I've downloaded a data set that I am interested in. However, it is in .mat format and I do not have access to Matlab.
I've done some googling and it says I can open it in SciLab.
I tried a few things, but I haven't found any good tutorials on this.
I did
fd = matfile_open("file.mat")
matfile_listvar(fd)
and that prints out the filename without the extension. I tried
var1 = matfile_varreadnext(fd)
and that just gives me "var1 = "
I don't really know how the data is organized. The repository described the data it contains, but not how it is organized.
So, my question is, what am I doing wrong in extracting/viewing this data? I'm not committed to SciLab, if there is a better tool for this I am open to that.
One options is to use Octave, which can read .mat files and run most Matlab .m files. Octave is open source with binaries available for Linux, Mac, and Windows. Inside of Octave you can load the file using:
load file
See Octave's manual section 14.1.3 Simple File I/O for more details.
In Scilab:
loadmatfile('file.mat');
(Source)
I had this same interest a few years back. I used this question as a guide. It uses Python and SciPy. There are options for NumPy and hd5f as well. Another option is to write your own reader for the .mat format in whatever language you need. Here is the link to the mat file format definition.

Save currently running script in Matlab

Is there a way of saving the currently running script in Matlab? I have a script which automatically takes a backup of a set of scripts although if I have changed the current script then the saved version will be out of date.
Perhaps its possible to call some java?
Thanks
Somewhere on Yair Altman's site (see link in my other answer) he also referred to a blog entry about editorservices, which was introduced with MATLAB R2009b.
editorservices.getActive().save
should do what you want.
Okay, all I write here I learned from undocumentedmatlab.com by Yair Altman, in particular by looking into his EditorMacro.m... great stuff!
I'm assuming that Itamar Katz understood you correctly and that you are running unsaved code from the editor by using "Evaluate Cell" or "Evaluate Selection"; you want your code to realize that it is not saved and save the version currently displayed in the editor to some other location.
I have not found a way to save the file directly to the original location, but at least I have found a way to access the current text. You can then use fprintf to save it to wherever you want. I have tested this in Matlab 7.11 (R2010b); if you have a different version you'd need to dig through EditorMacro.m to find the correct code for Matlab 6.
if com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor.isDirty
thisdocument=com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor.getDocument;
thisdocument_text=char(thisdocument.getText(0,thisdocument.getLength));
fid = fopen('backupfile.m','w');
fprintf(fid, '%s', thisdocument_text);
fclose(fid);
else
% saved file is unmodified in editor - no need to play tricks...
...
end
So the if-condition checks if the currently active editor window contains a file which is not saved ("dirty"); if it is, we need to retrieve the current version of the code (into variable thisdocument_text) and save this string to some file.
Does this help?