2

I have a loop that each time has new data in an array. I would like to save that array in a .mat file after each insertion of the loop and I want the name of the file to change with the loop value. Say I go through my loop 5 times, I want to have 5 files array_1.mat array_2.mat array_3.mat array_4.mat array_5.mat

To test my idea I wrote:

for A=1:10;
filename = sprintf('array_%d.mat', A)
save('-mat', filename, 'A');
endfor

after running this code in octave, I do get 5 files with the correct names but they don't seem to be .mat file, I can't load them again into octave. I have tried a lot of other small syntax changes and nothing seems to work. Can anyone tell me what i am doing wrong and/or give my a test example that changes the name of a.mat file with the loop variable. Thanks

1 Answer 1

1

That works for me so I'm guessing your problem is on the load command. How are you loading the files? You should load array_5.mat

Sign up to request clarification or add additional context in comments.

2 Comments

hmmm... It does seem like it should work. When I try load array_5.mat I just get the error: load: unable to find file array_5.mat but I can clearly see that the file is in the current directory. Though when I try to directly open the file by clicking on it, it says "There was a problem opening the file". I am running Ubuntu and Octave version 3.2.4. Is that what you are running?
@Elena try cd up and down one directory level. I think there was a bug in old versions about that (and you are using a quite old version). I'm using Octave 3.6.2 on Debian. You can build it from source (it's actually not that hard on Ubuntu, see wiki.octave.org/Debian ) or you can use one of the unofficial binaries wiki.octave.org/Octave_for_GNU/Linux#Unofficial_binaries )

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.