How can I change the name of the file being saved without editing the code? MatLab - matlab

I am working on an experiment that take a lot of data samples and save it to different video files. For example, I take data and save it to a file called "slowmotion.avi" and then I take another set of data and save it to another file called "normalspeed.avi".
I am trying to find a way that I could change the name of file being saved without editing the code. The way I am using right now makes me have to open the code and change the name of the file directory within the code and then save the code. I want to make it a lot faster and easier to use.
I have tried the following code to fix this problem but it doesn't work.
graph=input('Graph of experiment: ');
vidObj = VideoWriter('%3.1f.avi\n',graph);
.....
Hope I didn't confuse you.

A possible solution:
graph=input('Graph of experiment: ','s');
vidObj = VideoWriter([graph,'.avi']);
The 's' in the input() function indicates that the expected input is a string, and [graph,'.avi'] simply concatenates both strings.

Related

How to save streaming data to Matlab .mat file

I am trying to save real-time streaming data obtained from hardware to Matlab workspace, I use the following command: My issue is, it only saved the last set of data, but not all data.
To save all variables from the workspace in binary MAT-file, test.mat, type
save test.mat
When I tried with this
save('test.mat','-append'); ,
it makes my program halt, so I would like to know what is the correct way to achieve this?
They have same name and they are constantly overwritten, I did not get error message, I still get the file saved but I noticed that it only showed the latest set of data, what should I do to avoid this? I want it to save every set at each time step
The correct syntax for appending using save is
save(filename,variables,'-append')
This will save append all new variables and overwrite variables already in the filename.mat with the updated values.

How to add input parameters for matlab application execution

I'm writing a script in MatLab and I need to execute a program (written in C) as one of the lines (it generates an output file).
My current code is:
!collect2.exe infile.csv <-- I want to be able to change this to a variable but I can't
My question is, is there a way for me to either:
A. put a variable in place of infile.csv such as
!collect2.exe filedir
or
B. run multiple files without a variable
Thanks in advance :)
Edit:
filedir = input('What is the directory with quotes?');
!cd /
cmdString = ['cd ', filedir];
system(cmdString);
Edit #2:
Never mind, I fixed the issue. Thanks for all of your help!
Use the system function.
Example:
filename = 'infile.csv';
cmdString = ['collect2.exe ', filename];
system(cmdString);
you can create a variable called filename, per your example it would be
filename='infile.csv';
or alternately have you tried using this to launch multiple files at once?
!collect.exe {infile.csv,infile1.csv,infile2.csv};

Open .mat file in matlab or unix - new user

I am going through someone's data analysis files (created in an older version of matlab) and trying to find out what a particular .mat file is that was used in a matlab script.
I am trying to load a .mat file in matlab. I want to see what is in it.
When I type...
load ('file.mat')
the file loads and I see two variables appear in the workspace. jobhelp and jobs.
When I try to open jobs by typing the following in the matlab command window...
jobs
the response is..
jobs =
[1x1 struct]
Does this mean that there is only a 1 x 1 structure in the .mat file? If so, how in the world do I see what it is? I'm even happy to load it in unix, but I don't know how to do that either. Any help would be greatly appreciated as I have a few files like this that I can't get any information from.
Again, a new user, so please make it simple.
Thanks
It means that jobs is a cell array {} and within this cell array is a structure defined
To see the structure and its contents type jobs{1}
I think you are dealing with a SPM5 Batch-File. This variable is an image of the tree-like structure you can see in the Batch-Editor of SPM. Your job consists of one subitem (stats) which could have various subsubitems (like fMRI model specification, model estimation and so on).
To access this structure on the command line just proceed like Nick said:
Each level is a separate cell array that you can access with {#} after the name of the level. Example: jobs{1} shows you that there is a subitem named stats.
Subitems in structs are accessed with a dot. Example: jobes{1}.stats{1} shows you the subitems of the stats-entry.
Notice that there could be more than one entry on each layer: A stats module could (and probably would) contain various subitems. You can access them via jobs{1}.stat{2}, jobs{1}.stats{3} and so on.
The last layer would be the interesting one for you: The structures in here is an image of the options you can choose in the batch-editor.

relation between main GUI's and sub GUI's

I have two GUIs namesd masir and SetOut
SetOut GUI is a sub GUI for masir(pressing a button on masir will open SetOut)
To access the data of masir in SetOut I have these 2 lines of code:
masirGUIhandle = masir;
masirGUIdata = guidata(masirGUIhandle);
but running these 2 lines will run the opening function of masir as I work in SetOut(In opening function I have set some initial values for my variables and now I don't want those initial values ,I need changed values for my variables) so I dont want the OpeningFcn of masir GUI to be runned ,I just need to have access to masir data in SetOut
What can I do to fix the problem?
Can any one help me about this answer and explain me more?
I use this easy way for data sharing between GUIs
%In the end of OpeningFcn of Main GUI
setappdata(0,'HandleMainGUI',hObject);
%When you want to edit shared data you must get the handle
HandleMainGUI=getappdata(0,'HandleMainGUI');
%write a local variable called MyData to SharedData, any type of data
setappdata(HandleMainGUI,'SharedData',MyData);
%get SharedData and save it to a local variable called SomeDataShared
SomeDataShared=getappdata(HandleMainGUI,'SharedData');
Don't forget to clean up the data shared in the CloseReqFcn of you main GUI
HandleMainGUI=getappdata(0,'HandleMainGUI');
rmappdata(HandleMainGUI,'MySharedData') %do rmappdata for all data shared
Remember that your GUIs might try to getappdata that doesn't exist, you should first test if it does exist
if (isappdata(0,'HandleMainGUI') & isappdata(HandleMainGUI,'MySharedData'))
%get, set or rm appdata
else
%do something else, maybe loading default values into those variables
end
Tell me more aboute which line of code should be written in MainGUI and which line should be written in SubGUI?
And tell me what does the responser mean by CloseReqFcn?
Well let me summarize how I see the problem.
You want to read the data from SetOut with out creating it? That's not possible like this as the data will be created when the window is created.
A nice and systematic way around would be doing it object oriented (see Model-View Controller Pattern) You can more or less copy an example from my answer here (Example for Event - Observer)
But if you'd like to stick with your code I also have some ideas:
If you don't want the window to show you could set it invisible with set(theGUIhandle,'Visible','off')
While the window is not closed you can obtain the data with getappdata(theGUIhandle)
If you want the data after the window is closed you need to have a function that stores it outside the window.

saving segmented images from a number plate

hye everyone i m doing my project "automatic vechicle identification".i have to design software in matlab,i have done extraction of plate region ,segmentation of characters,...now i want to save these segmented characters so that i can further recognize these character from a data base......any body can help me please feel free to write to me, thanks in advance
So if you have some data, myData then you can just issue a command save myData and you will have a new file in the current directory named myData.mat. To load the data later, just type in load myData and then you will have a new variable in the workspace named myData. There's lots more you can do with this, so you should check out help save.
Alternatively you could use a database. I've never actually used a database in Matlab, but there seems to be plenty of information about how one would go about doing this: http://www.mathworks.com/help/toolbox/database/ug/database.html