How can I get Octave GUI to load/read .m files correctly in editor and console? - octave

I am taking a class on using Octave for machine learning algorithms, and as part of the assignments, they provide a series of .m files to build upon with our own code as well as to run for submission credit through the auto-grader. My problem is that the .m files load perfectly fine in a regular text editor program like Atom or Notepad, but in Octave, the files are best described as nonsense, and thus will not run in the console. If I open the files in a regular editor and copy/paste over the crazy into Octave, it seems to save it and reopen fine. But, I have close to 20 files for the first project alone, and this solution is untenable in the long run. I have a screenshot of how it's loading. Is there some setting I need to change? Uninstall/reinstall Octave? I'm new to Octave and the Octave GUI, and I'm striking out with Google for a solution. I am using version 6.2.0. Thank you for any help/advice!
screenshot of how octave is loading my .m files
Update: I responded to this in a comment below, but I tried loading it another way into Octave GUI and received the following error: ">> error: load: unable to determine file format of 'C:/Users/sophi/documents/octave/assignment_1/computeCost.m" This tracks for me because it makes sense why it would open the files in such a weird way. It's simply not sure what they are. However, I created my own simple functions from scratch to test, saved them as .m files, and was able to run them perfectly fine. I'm including one of the files below. Maybe there's a key in the formatting of the files offered by the class which is impacting Octave's ability to process it correctly?
function plotData(x, y)
%PLOTDATA Plots the data points x and y into a new figure
% PLOTDATA(x,y) plots the data points and gives the figure axes labels of
% population and profit.
figure; % open a new figure window
% ====================== YOUR CODE HERE ======================
% Instructions: .... goes on about assignment
% ============================================================
end
MOST RECENT UPDATE: The plot thickens. Yesterday, I was able to open the files I created and run them in the Octave environment, and I (wrongly) assumed they would still work today. They are doing the same stupid thing as the files included by the course. I checked inside preferences for the editor, and it says it is loading and saving them as IBM273 if that helps. Thank you for everyone has pitched in ideas. I really appreciate it!

It was 100% the encoding. I thought it was strange it was saving/loading in IBM273, so I switched it to UTF-8. Almost all the files are working now. The only ones that aren't are the ones I was trying to copy/paste yesterday to see what was going on with the load problems and the basic new problems I wrote. So I deleted everything, redownloaded, and set the default UTF-8 going forward and voila! Solved! Thanks again!

If you want to open a .m file in octave, Try this solution
It is necessary to declare a current directory before saving a file, loading a file, or running an M-file. By default, unless you edit the Octave shortcut, the current directory will be .../Octave/work. After you start Octave, change the current directory by either using the toolbar at the left-hand side of the screen, or entering the path in the bar at the top.
To open an .m file, you can use file -> open, or type
open filename

Related

PlotlyJS.jl "savehtml" not defined

I need to share an interactive plot made using the PlotlyJS package in Julia. According to the documentation of the package PlotlyJS.jl, I need to use the "savehtml" function and set "js" argument to ":embed" in order to view it offline (screenshot attached). However, I got an error "UndefVarError: savehtml not defined". Can anyone tell me what may cause this problem?
FYI, the "savefig" function can save the plot into an HTML but the HTML cannot be viewed on other machines.
It is also acceptable if there is another way to save an HTML plot that can be assessed from other machines. The interactive plot is generated by PlotlyJS.jl.
Thanks very much in advance.
This creates a standalone file that can be used on other machines.
However, those other machines need to have access to the internet:
p = PlotlyJS.Plot(sin.(1:0.1:10))
open("f.html","w") do f
PlotlyJS.PlotlyBase.to_html(f, p; include_plotlyjs="cdn", full_html=true)
end
I just checked that this is as far as you can do as of today (version v0.8.18) as there is a bug in the source code of PlotlyBase.

Octave pop up message

I am running Octave 4.4.1 on MacOs Catalina 10.15.7. For some weeks I have been having this message poping up when a code is running: "
It seems that [name of script] has been modified by another application. DO you want to reload it?
I click Yes each time it pops up, but when the code is running, it just keeps coming back, and sometimes Octave becomes unresponsive although the script has finished running
All I could find on the internet were either some old posts with answers about outdated Octave versions, or very complicated stuff that I would not be able to implement.
Any one knows why this happens, and what to do about it?
thanks a lot
This message is exclusive to the GUI version of Octave, and it comes up if you have a file open for editing in the Octave GUI Editor window, and the file's contents change due to a process unrelated to the Octave Editor.
E.g. you may also be editing the file on an external text editor at the same time? Or your script may be copying / generating a new file under the same name as a file that you've got open in the editor, effectively overwriting the now-out-of-date version that's still being displayed in the Octave Editor?
Octave gives you this warning to prevent you from 'saving' in your editor, and therefore undoing any changes that had been made by the external process in the meantime.

Unexpected Errors on publishing figure to html by MATLAB in Linux

I am using MATLAB to publish HTML report. In the .m script, I have some plot functions to produce graphs. While I was running the script in the MATLAB GUI, it works perfectly fine as I expected.
However, the problems came, I need to run the script from the command line such that to save time, when I ran the script from command line, the HTML file was still produced but all the figures became distorted. All of them went to resolution of 520 x 460, I didn't really know why this happen.
To solve the problem, I tried to change the publish option specified in this page: http://www.mathworks.com/help/matlab/matlab_prog/specifying-output-preferences-for-publishing.html
But they don't seems to help.
Do anyone of you have any ideas? Any help will be appreciated.

CHM compiles fine, but won't open

I use a program that spits out HTML and hhp projects containing data from my databases.
I then compile that hhp with Microsoft HTML Help Compiler (hhc.exe).
It works well, but unfortunately for few projects, hhc compiles fine, but chm file is unusable.
It reports "Cannot open the file: mk:#MSITStore‎: FileName"
I have no problem with other chm files on my system. I have no problems with other chm I compile. If I remove several topics from my project produced file works again. It doesn't matter what topics I remove. Files that don't work are almost twice the size of files that work, even tho the html and project file is almost the same (very few changes), which leads me to think compression fails silently if size or structure of some file isn't right.
Does anyone have experience like this and what could be the reason?
For those that want to see example, this project will compile and work fine:
Working chm project
And this one compile but fail to open:
Chm that fails
I experienced the identical problem. The CHM was double the usual size and could not be opened. The CHM compiler did not report any error. Removing any random HTML file enabled opening the CHM. I generated many other CHMs on the same day, and all the others were OK.
I worked around the problem in the following way:
I added a very small HTML file to the project. It is a copy of one of the other files in the project, so if a user finds it in a search, it does no harm.
I entered the file name in the HHP.
I recompiled the project in the CHM compiler.
The CHM shrank to the normal size, and it opens normally.
I had exactly the same problem and can say it's all a matter of size and most likely an error in the compression module of hhc.
When I added some lines of documentation the size of the CHM-file increased from 1.6 to 3.1 MB and it could not be opened anymore.
This problem could not only be fixed by removing files but also by adding files.
So I wrote some additional documentation, added it to the project and everything was fine again.
There are a number of reasons why the MS HH compiler may crash.
(1) Invalid filenamesfile and file
The HTML Help compiler does not like some filenames e.g. spaces in a filename can still cause some minor problems with HTML Help. Best to replace spaces with underscores. Avoid "#" in file and folder names.
Try and stick with these characters _, a..z, A..Z, 0..9.
Do not use periods apart from in the normal file extension. Example: A filename such as xxx.h001.gif is identified incorrectly as a HTML file. The compiler then attempts to parse the binary file and crashes.
Do not use file or folder names containing ".chm".
(2) Avoid compiling on a network drive and try to compile on local drive.
(3) Use MJ’s Help Diagnostics to ensure that all the help viewer components are properly installed and registered.
http://helpware.net/downloads/#MJs
(4) Delete the file “hh.dat”, which you should find in this subdirectory:
\Documents and Settings\%username%\Application Data\Microsoft\HTML Help
This file stores information about all the HTML Help files on your system (Favorites, window size and position, etc.), and can cause the files to misbehave if it has somehow been corrupted.
(5) You need to debug your help system. You need to identify the file(s) that are crashing the compiler.
I normally remove sections of the web by renaming or moving folders and files, then recompile. Keep adding and removing sections until the compiler does not crash. Eventually you will find one or two files that are causing the problem. You may also need to debug these files by temporarily removing sections of the HTML file.
I see 0 byte files in the input? Maybe the compiler can't handle that?

How to change the load path in Octave

I have a problem with loading images and editing scripts in Octave. I think Octave has the wrong path or something. When I say 'edit', it says:
sh: 1: emacs: not found
What does that mean?
I'm pretty new to both Octave and MATLAB, but when I'm at school using MATLAB, for example, writing the command 'edit' works...
How do I know where to put files I want to load in Octave, and how do I change the path?
The problem is not with your path, the problem is that you didn't set up EDITOR (see help EDITOR and the editor option at help edit). As you have no environmental variable for it, it defaults to emacs so when you run edit, it tries to open the file in emacs and fails because you don't have it installed. Set up EDITOR for your text editor of choice at .octaverc file (If I remember correctly, the text editor to use is set as a persistent variable inside edit.m so you'll have to restart octave) or an environmental variable (I'd recommend this one).
It works in matlab because they made their own text editor. Octave is not a text editor, it's a programming language, it would be a waste of time to reinvent the wheel, and you should be able to choose whatever you are comfortable to code with.