M-file with issue on linux (clear all; close all; clc; not working)

Hello

I’ve been facing an issue or at least an strange behavior with Octave on Linux.

I made and m-file and as I do in Matlab, I always start the script with the 3 rows indicates below:

clear all;
close all;
clc;

If I run those function from Command Windows they work very well. If I run them from scirpt M-file , they don’t work, and the results is buggy. So any change I do in my script, or if I just run the script again, I need to run those tree functions manually in the command windows all time. Is this an issue or should I do something different in Octave to make those function run properly in the m-file?

Below my current OS detail, the Octave was installed from pamac trough flatpack

System:    Kernel: 5.14.0-0-MANJARO x86_64 bits: 64 compiler: gcc v: 11.1.0 Console: tty pts/1 Distro: Manjaro Linux 
           base: Arch Linux 
Machine:   Type: Desktop Mobo: Gigabyte model: GA-870A-UD3 v: x.x serial: N/A BIOS: Award v: F5 date: 08/01/2011 
CPU:       Info: Quad Core model: AMD Phenom II X4 965 bits: 64 type: MCP arch: K10 rev: 3 cache: L2: 2 MiB 
           flags: lm nx pae sse sse2 sse3 sse4a svm bogomips: 27336 
           Speed: 800 MHz min/max: 800/3400 MHz Core speeds (MHz): 1: 800 2: 2200 3: 800 4: 800 
Graphics:  Device-1: Advanced Micro Devices [AMD/ATI] Ellesmere [Radeon RX 470/480/570/570X/580/580X/590] 
           vendor: Micro-Star MSI driver: amdgpu v: kernel bus-ID: 01:00.0 
           Display: server: X.Org 1.20.13 driver: loaded: amdgpu,ati unloaded: modesetting,radeon resolution: 1920x1080~60Hz 
           OpenGL: renderer: Radeon RX 570 Series (POLARIS10 DRM 3.42.0 5.14.0-0-MANJARO LLVM 12.0.1) v: 4.6 Mesa 21.2.1 
           direct render: Yes 
Audio:     Device-1: Advanced Micro Devices [AMD/ATI] SBx00 Azalia vendor: Gigabyte GA-880GMA-USB3 driver: snd_hda_intel 
           v: kernel bus-ID: 00:14.2 
           Device-2: AMD Ellesmere HDMI Audio [Radeon RX 470/480 / 570/580/590] vendor: Micro-Star MSI driver: snd_hda_intel 
           v: kernel bus-ID: 01:00.1 
           Sound Server-1: ALSA v: k5.14.0-0-MANJARO running: yes 
           Sound Server-2: JACK v: 1.9.19 running: no 
           Sound Server-3: PulseAudio v: 15.0 running: yes 
           Sound Server-4: PipeWire v: 0.3.34 running: yes 
Network:   Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet vendor: Gigabyte driver: r8169 v: kernel 
           port: 9e00 bus-ID: 06:00.0 
           IF: enp6s0 state: up speed: 1000 Mbps duplex: full mac: <filter> 
Drives:    Local Storage: total: 2.48 TiB used: 1.73 TiB (69.6%) 
           ID-1: /dev/sda vendor: SanDisk model: SSD PLUS 240GB size: 223.58 GiB 
           ID-2: /dev/sdb vendor: Corsair model: Corsair Force GS size: 119.24 GiB 
           ID-3: /dev/sdc vendor: Patriot model: Burst size: 223.57 GiB 
           ID-4: /dev/sdd vendor: Crucial model: CT120BX100SSD1 size: 111.79 GiB 
           ID-5: /dev/sde vendor: Western Digital model: WD20PURZ-85GU6Y0 size: 1.82 TiB 
Partition: ID-1: / size: 210.4 GiB used: 93.47 GiB (44.4%) fs: ext4 dev: /dev/sdc1 
Swap:      ID-1: swap-1 type: partition size: 8.8 GiB used: 0 KiB (0.0%) dev: /dev/sdc2 
Sensors:   System Temperatures: cpu: 39.4 C mobo: N/A gpu: amdgpu temp: 53.0 C 
           Fan Speeds (RPM): N/A gpu: amdgpu fan: 182 
Info:      Processes: 268 Uptime: 1h 1m Memory: 7.76 GiB used: 2.49 GiB (32.0%) Init: systemd Compilers: gcc: 11.1.0 
           Packages: 1446 Shell: Bash v: 5.1.8 inxi: 3.3.06 

Can you show the buggy running m-files? Those three commands shall in general not bother Octave whether being run from a script or command-window.

Hello skiko1056, thanks to help me again.

To how you the bug it will needs me to put some screenshot here. I’m also putting the complete code, it’s short one to make a lesson for a friend. The m-file relates to a “Compound interest”, very simple, you invest a capital of 1000 for 12 months with 6% rate. So I run the program the first time and it works well generating the results and the graphic, them and change the capital from 1000 to 2000 and ask to run again, then it bugs, it not clear all variable, it not clear the command windows and it don’t close the graphs, in addition it show off the variable “juros” in the command windows without being asked.

Note.: Once i’m new in the forum I can only post 3 embedded images.

screenshot #1 - m-file as it is (see that work space is clear)

screenshot #2 - Command Window print

screenshot #3 - Figure plot

screenshot #4 - Capital changed from 1000 to 2000

screenshot #5 - Command Window buggy
(it didn’t applied the commands, close all, clear all, clc) in the workspace the c remains equal to 1000 and the figure wasn’t updated. If i run those 3 commands in the command windows, them the script will run properly)

below the complete script

% script m-file

clear all;
close all;
clc;

c=2000 %valor do capital
taxa=0.06 % taxa de juros ao mes
tempo=12 % tempo em meses

juros1b=c*(1+taxa);
juros2b=c*(1+taxa)^2;
juros3b=c*(1+taxa)^3;
juros4b=c*(1+taxa)^4;
juros5b=c*(1+taxa)^5;
juros6b=c*(1+taxa)^6;
juros7b=c*(1+taxa)^7;
juros8b=c*(1+taxa)^8;
juros9b=c*(1+taxa)^9;
juros10b=c*(1+taxa)^10;
juros1ab=c*(1+taxa)^11;
juros12b=c*(1+taxa)^12;

k=1;

while(k<=tempo)
  juros(1,[k])=c*(1+taxa)^k;
  k=k+1;
end;

x=linspace(1,12,12);

plot(x,juros)

The variable juros shadows the script file name.
Either change the variable name or the script file name.

1 Like

thank you mmuetzel, strange but yes, once the m-file script has the same name of one variable looks like it created the issue. Anyway it remains strange why running the commands manually the script works fine.

Maybe Octave could show a warning about the filename being equal to one variable and this situation could lead to bugs. If I see the warning, would be very easy to fix it.

Thank you all for the help

1 Like