1

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!

7
  • 2
    It looks like Octave is configured for a different locale than the files are. Apr 19, 2021 at 18:54
  • What Cris is saying is that if octave is configured to read e.g. Chinese characters, yet you are using Thai characters, it may go wrong. The countries are just random examples Apr 19, 2021 at 19:14
  • It could be, but I followed the instructions and am a bit confused. I decided to close it and try loading the workspace where the code is and got this message: ">> error: load: unable to determine file format of 'C:/Users/sophi/documents/octave/assignment_1/computeCost.m'" I suspected this because of the nonsense it was loading when I tried to load the files directly or open them in octave. I'm just not sure how to get them to determine the format and open them correctly.
    – Miss E
    Apr 19, 2021 at 19:15
  • The class is in America, and I'm American so I don't think that's the case. There aren't any foreign characters, and everything looks fine. It just doesn't seem to understand the .m format.
    – Miss E
    Apr 19, 2021 at 19:17
  • @MissE are you able to upload an example of the file to examine for encoding issues? (i.e. don't simply copy paste the contents from your editor) Apr 19, 2021 at 21:51

2 Answers 2

1

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!

0

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

1
  • Thanks for responding! Unfortunately, that's not working either. It's still opening it incorrectly. I'll upload a sample file and update the original post in case people want to see it on their screens!
    – Miss E
    Apr 20, 2021 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.