Saving array to variable name Octave - save

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

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

Related

Write specific bytes inside a file using lua

I want to write a specific byte inside a .txt file, for example:
Text File
Something
Code
Som4thing
I want to do like that, but without overwriting the whole file using io.write().
I hope it was easy to understand my question.
First, you need to figure out what mode to open the file in. r won't let you write, so it's out. a and a+ will only ever let you write to the end, so they're out. w and w+ erase the whole file, so they're out. That leaves r+.
Next, you need to get to the right place in the file. The seek function does that. In your case, you want to go to 3 bytes past the beginning.
Finally, simply write your data and close the file.
local file = io.open('filename.txt', 'r+')
file:seek('set', 3)
file:write('4')
file:close()

Can I avoid hardcoding file locations in SPSS syntax?

I'm using SPSS 25 syntax to open and process a set of datafiles. I would like these syntax files to be as portable as possible. For that reason, I want the user to be able to select the file locations at runtime without having to recode the syntax itself.
I'm running Windows 10, although hopefully that doesn't matter. I do have the Python plugin for SPSS, although ideally this would be a base SPSS syntax solution.
In SPSS right now, I'm doing this:
GET
FILE='C:\Users\xkcd\studies\project\rawdata'+
'\reallyraw\veryraw.sav'
PASSWORD='CorrectHorseBatteryStaple'.
DATASET NAME Demo WINDOW=FRONT.
In R, I would do this:
message("Where is the veryraw.sav file?")
demo<-fread(file.choose())
Ideally, the user would, at runtime, select the individual files one at a time.
Less ideally, the user would select a folder in which all of the files, with known names.
I could use FILE HANDLE so that the user would only have to hardcode a few folder locations, but that's less than ideal - I really would rather that the user isn't editing the syntax at all.
Thanks in advance!
Following up on the idea of a fully automated process - the following code will work assuming there is a specific file name you need to run your code on, and only one copy exists in the folder you are searching. This is possible to run on drive C: directly, but will take much less time to run if you can narrow down the path:
* this will create a text file that has the path of the required file.
HOST COMMAND=['dir /s /b "C:\Users\somename\*required file name.sav" > C:\Users\somename\tempname.sps'].
* now to read the name and put in in a handle.
DATA LIST file = "C:\Users\somename\tempname.sps" fixed / pth 1-500 (a).
exe.
string cmd(a500).
compute cmd=concat("file handle myfile / name='", rtrim(pth), "'.").
write out="C:\Users\somename\tempname.sps" /cmd.
exe.
* inserting the new syntax will activate the handle.
insert file = "C:\Users\somename\tempname.sps".
Now you can use the handle myfile in the syntax, e.g:
get file=myfile.

Can not open new files on SD with NodeMCU FATFS module

I'm using the NodeMCU environment to write a Lua script for the ESP8266. It uses the FATFS module to create several files with the following pattern:
LOG_xxxxyymmdd_hhmmss.txt, where xxxx: #file(incremental), and the rest is a timestamp.
I was running a test, creating one file, filling it with a small amount of data (~200 bytes), closing it, and repeating this for X times. After the first hour had passed, the files stopped being created. Here is the list of files created successfully:
<script src="https://pastebin.com/embed_js/0xn3MBQt"></script>
And here are some filenames it couldn't create:
LOG_0193000101_005909.txt
LOG_0194000101_005908.txt
LOG_0000000000_000000.txt
LOG.txt
I'm really troubled by this. Is there some kind of filename size limit so that when searching for files during open(), it returns an error because of a name ambiguity or something like that? If anyone has a clue about this, please tell me so I can test it. Thanks.

getting a substring from a text file for later use

I have a text file that contains version information. There are multiple lines, but the specific line i need looks like this:
#define SW_VERSION "3.4.3.1 R3 08-06-12"
I specifically need the 3.4.3.1 R3 from the text file.
My first thought was to do execute a short script that would grab this data out and use a set for later use, though i am having quite a bit of trouble getting it to work.
I ran this: Find /I "#define SW_VERSION" C:\SW\bin\SW_Version.txt
and it showed me the line in the file that i expected, but i couldn't figure out how to parse it afterwards. Help?
You can write a custom task for Ant.
Your custom task would parse the version line and extract the information you need.

rails reading lines of file before upload with paperclip

I am trying to upload a file in rails (using paperclip), and I want to process some of the file data before letting paperclip send it off to s3 storage. In my controller, I just grab the file parameter (which does give me a file) and then I try to read the lines into an array
csv_file = params[:activity][:data]
array = IO.readlines(csv_file.path)
The problem is, I'm only getting the last line of the file. I tried using .rewind, but still get just the last line.
I dislike readlines and I always use regular expressions. Try this.
End of line - \n
Handy block structure to ensure that the file handle is closed:
File.open(csv_file.path) do |f|
a = f.readlines
process a...
end
Reading a whole file into memory might not be a good idea depending on the size of the files.

Resources