Save data in MATLAB - matlab

I am trying to save a variable in .mat format and update and APPEND the NEW contents of THIS variable each time a loop is finished to avoid memory blow up. I have searched a bit and think the best way is structures. But still think there should be an straight way to do that. Anybody can give me an example to how to do that?

You could try using matfile to write without loading the file.

Related

Re-reading CSV method for bufferedSource

I'm trying to read a csv and gather two types of informations.
I need to read it once to get the number of lines that my csv contains.
I need to go back to the top of the csv and re read it again to retrieve the values.
I'm looking for something similar to seek(0) in java for bufferedSource
I've tried to close and re open the buffer but I think I'm overthiking it.
I also read through the source library but nothing came close to what I'm looking for.
PS:I know this is not optimized however my first read will basically enable me to create an array to store the values I'd retrive from the second read(and not a list).
I would take any clue you might have to offer !
Thanks a lot

how to get clipboard data to a variable in intersystems cache?

consider i have some data copied to my clip board. I would like to get those into a variable(not in a way of pasting on terminal window),so i can able to make use of that variable.
can any one suggest any way of doing it.either by using script execution or anything using class or etc.
Maybe you will give more information about your application: WEB/ZEN/CSP, TUI, other types.
Anyway, Cache, do not have any special variables for clipboard.

How to read mat file and store in a variable

I have two .mat files. And I want to read these data of two mat files and store in variables A and B. This is my code, but I think it is not good. Can you help me store it without using matArray in matlab? (Varibale matArray is born when you call load function)
load input1.mat;
A=matArray;
load input2.mat;
B=matArray
Thank you so much
You had it right. The variable name that you have when you save the file is the name that will appear in the workspace when you load the file again. Best you can do:
load('input1.mat');
A=matArray;
load('input2.mat');
B=matArray;
clear matArray
At least you'll get the space back at the end. There is, to my knowledge, no "rename" function in Matlab...
Of course if you know what you want to name the variable when you read it in, you should save it as such:
A = matArray;
save('input1.mat', 'A');
etc
Use an output argument with the load function.
A = load('input1.mat');
B = load('input2.mat');
The two arrays will now be fields of the structures A and B:
size(A.matArray);
plot(B.matArray);
If you choose to copy these into simpler variables, or stick with your current copying approach, you should know that the copy operation is extremely efficient. When you do A = matArray; A shares the data of matArray until one of them is modified. Therefore, if you delete matArray before modifying A, no extra memory is consumed by the copy.

.mat tree-like structure settting up pre-processing parameters

I have a further question about opening up a .mat file. It is a "tree like structure" which specifies the pre-processing steps for image analysis and is a SPM5 Batch-File. Is there an easier way to view this file than by moving through it section by section? I'm trying to update this for re-analysis.
For example, by typing...
jobs{2}.spatial{2}.coreg{1}.estimate
I can see what parameters are set for estimation. However, is there a way to get an output of the entire tree like structure? Or is there an easier way to view the final levels of the tree like structure?
I'm hoping that this makes sense, sorry again, I am a new user.
As far as I know Matlab does not have any built-in way of displaying the full content of recursive structs. However, if you know your programming abc, writing a recursive function for displaying it will not be a huge task. Simply start at the top, loop through all fields using fieldnames(...), determine for each field if it is a leave or a struct and possibly decent and repeat.
Regards

what happens when you load a directory?

I am trying to learn some simple matlab code posted by my professor, and the first line goes somehting like
load /class/mat121/lab1/data
I've never seen "load" used like this before, what does it do? does it load all .m files in the directory?
I also see a lot of custom functions in the code, such as "T()", "Lon()", "Lat()" etc, they aren't standard matlab functions therefore I am assuming they are imported from that directory?
thanks
Title is incorrect, because "data" is not directory.
You can refer to load function.
Anyway,
/class/mat121/lab1/
this should be the directory path
data
this should be a file called "data.mat" which contains matlab workspace variable that is previously saved with save function.
So,
load /class/mat121/lab1/data
loads workspace variables from "data.mat" which is located under "/class/mat121/lab1/".
If you have access to matlab, the best thing to do would be to run the following commands and have a look at the results:
help load
help which
which T
help T
which Lon
which Lat
Running these commands should tell you:
What Load does
What which does
Where T is
What T does
Where Lon is
Where Lat is