I want to write the file name in the gui edit text and save edit text as my filename. Than I could be able to save filename as I wish. For instance; My file is an Neural network file which could be save as *.mat file; here is my code
%network_name is my edit text
name = get(handles.network_name,'string');
name = net;
save name
But it doesn't work I can't manage file name from edit text :(
It saves as name that l wrote next to save (name.mat). Thanks for your any answer...
Why name = net;?
That aside, if you want to pass the filename as a variable to the save function, you need to use this syntax instead:
save(name)
save name is the "command form", and save('name') is the corresponding "function form". As you can see you can only give string inputs when using command form, whilst you actually want to pass a variable.
To conclude: if you are passing variables to a function, use function form.
If you want to save particular variables, use:
save(name,'net');
Note that name (which we want to be the string contained in the variable) isn't in quotes and net (the name of the variable we want to save) is.
A warning about this is actually buried in the documentation for save.
Do not use command form when any of the inputs, such as filename,
are variables.
save name
will save all of the variables in your workspace to a *.mat file called 'name'
Also your code is basically overwriting itself, line 2 sets the variable name to be a string, but then line 3 writes some data net to that variable.
I'm a little confused as to exactly what you want but I think you want to save the variable net to a mat file with the name that you read in the string from get(handles.network_name,'string')
If that is what you want to do then its just
save(get(handles.network_name,'string'), net)
If you want to save all the open variabile in the workspace then its just
save(get(handles.network_name,'string'))
Related
I want the user of a script I'm writing to be able to navigate to a file containing their data and to load the data into the workspace. For example, if a csv file contains two cells with the values 1 and 2 respectively, I want the user to simply choose this file and those two values will be assigned to a variable in the workspace.
I have looked at using:
filename = uigetfile('*.xlsx','*.csv')
But that just returns the name of the file. Perhaps I could construct a full path to where the file they choose is found, and then read it in that way (using xlsread or csvread) but I think I'm probably missing something here. It seems that there should be a more straightforward way of doing it.
I believe that you're looking for the uiopen() function. This function will:
Open dialog box for selecting files to load into workspace.
On default, this function will display in a file explorer dialog box with the filter set to all MATLABĀ® files (with file extensions *.m, *.mlx, *.mat, *.fig, *.mdl, and *.slx).
However, you can import data from data files like CSV files and spreadsheets as well. Simply select the (All Files) option for the Files of Type field.
Once you've selected the data file you're interested in, you will be prompted with another GUI object that previews the data you are about to load into MATLAB's workspace. If you're satisfied with the format of the variables presented in the preview, simply hit the green check-mark at the right-side of the tool-box ribbon in the GUI object and, huzzah, all of the data file's contents have been loaded into separate variables (named according to their respective headers).
Alternatively, though this is undeniably a longer-winded and uglier approach, if you'd like to use the filename returned from uigetfile('*.xlsx', '*.csv'), you could use the importdata() function. This will output a struct that contains each of the variables from your data file as a separate field:
[filename, pathname] = uigetfile( ...
{'*.csv;', 'CSV file (*.csv)';
'*.xlsx', 'Excel Spreadsheet file (*.xlsx)'; ...
'*.*', 'All Files (*.*)'}, 'Pick a File to Import');
full_filename = fullfile(pathname, filename);
[A, delimiterOut] = importdata(full_filename);
I Need to understand a very Long matlab file.
It is very tedious to put Breakpoints everywhere.
I wondered if there is an Option to track every possible variable at once ?
Something that would maybe store each variale in a text sheet and diaplays how they Change througout the code...
There are many many variables.
What I want to do is to create a scribt, where I can Input a list of variable names. The script then tracks those variable names within the program and exports them every time they Change.
Input: List of variables and programm Name (other script)
Content: Tracks variable in the Programm
Output: Table with tracked variables
Name_variable_1 |Value at line...|Value at line...|Value at line...
Name_variable_2 |Value at line...|Value at line...|Value at line...
.
.
.
Thanks.
You could maybe save the workspace periodically and then make a seperate MATLAB script that graphs the changes of the variables or writes out a text file for it?
I assume you're familiar with MATLAB, but just to be safe:
http://de.mathworks.com/help/matlab/ref/save.html
Just append the variable's contents to a text file or save the entire workspace and parse it later.
I would like to know how I can save the matlab output files (i.e. matlab workplace variables), by including original file name.
e.g. I open a file (filename.mat) with load filename.mat. Then I run a code to do calculation and I get some workplace variables (e.g. flow, pressure). I want to save those variables as filename_flow.mat and filename_pressure.mat.
I will use the same code on different filename, so I would like to know how I can save my variables as mentioned above (i.e. including the original file's name)?
FileToBeLoaded = 'filename.mat';
[pathstr,filename,ext] = fileparts(FileToBeLoaded)
load([filename ext]);
%// calculate stuff
FlowVariable = %// some calculation
save([filename '_flow'],FlowVariable)
The same of course works for other names as well. You pull apart the original file name to its actual name and extension, and use the original name, add something (_flow in this case) and save that. The default of MATLAB is already to save to a .mat file, so that's taken care of automatically.
I want to save a matrix as .text with a variable filename. Currently I'm saving my file using the function dlmwrite(name,matrix); This is only working with a pre-set filename. Is there a way to make the name of the file variable?
A window that pops up that ask for a filename to write to just as 'Uigetfile' does with opening a file would be ideal. Does anyone know if Matlab got a function just like that for writing text files?
You can use uiputfile to graphically get the file name. For example:
[filename, pathname, filterindex] = uiputfile('', 'Select file');
Then use dlmwrite to save a variable, say data, to that file:
dlmwrite(fullfile(pathname, filename), data)
I would like to set in a file all constant,parameters and then I can access from another class to any variable
for example const file const.m
FILE='file';
EDIT='edit';
COLOR_RED ='red',
COLOR_BLUE ='Blue'
START ='Start'
.....
...
and from any other files if I would like to access to any variable :
a = const.EDIT
so that I haven't to set a ='file' in each file.
How could I do that with matlab ?
how could also use enumeration ?
You don't need a struct just use the save command: http://www.mathworks.com/help/techdoc/ref/save.html and specify which workspace variables you want to save. If there are small like in your example, they will be easy to read in notepad for access not in matlab. In matlab just use the load function.
For example create two variable in matlab:
Var1 = 'Red'
Var2 = [1 2; 3 4]
now type
save('myData.mat');
this should create a file called myData.mat in your current working folder.
Now in another Matlab script you want to set a variable to have the value you saved as Var1 so you can go
NewVar = load('myData.mat', Var1)
And you can easily edit the values in the .mat file in a text editor such as notepad or gedit (or emacs or ms word or whatever) if you add the -ascii parameter when saving.
But you can also rewrite a variable by using save() again and specifying the variable name.