in data.m file I've defined simulink.parameters variables
when I load model , data are loaded in workspace and I would like to get the list of variables defined in data.m file
I tried :
a = whos('-file', 'data');
but this is used only for MAT files , is there an equivalent for m files ?
Thanks
Create a function
function ret_val=mywhos(path_to_file)
run(path_to_file)
ret_val=setxor('path_to_file',who());
This should do the job. In this way you read the file in a function workspace, after that you list all of the loaded variables and exclude the parameter you pass to the function itself. Returned are only the function names that are contained in the data.m file.
Call it by
vars=mywhos('data');
Related
I want to fetch file details like path of file, column names, and other things .In my job there are null values while using tfileproperties as shown in image added. look
if somebody can do something.
To Use tFileProperties you have to pass a valid file Path
What i suggest is to pass the file Path in a context variable as such
Then , pass the context variable in my case file_Input in the tFileProperties as such :
And if your files are stored in the same Folder you can use a tFileList component see the link below :
https://help.talend.com/r/en-US/7.3/tfilelist/tfilelist-standard-properties
PHP has the nifty include() function to bring in external files into the main script. Is this possible in Octave? I tried using load() but I keep getting an error: error: load: unable to determine the file format of 't_whse.m' which makes me think this is the wrong way to do this or that it's actually not possible in Octave.
You don't need to call load, as load is reserved for loading data from a file. Instead, you just want to call the script by name. This will (if it's actually a script) execute the script and make any variables that were defined in that script accessible to the calling script.
script1.m
disp('Beginning of script1');
script2;
fprintf('Value = %d\n', value)
disp('End of script1')
script2.m
disp('Beginning of script2');
value = 2;
disp('End of script 2');
I am working on a GA code in MATLAB. When I execute the following syntax in the command window
function[opt,fopt,histf]=ga(n,fitnessfct,decodefct,selectfct,stopeval)
I get the following error
Error: Function definitions are not permitted in this context.
You must define your function in another M-file named by ga.
1- Create a new script, M-file where you can you use "Ctrl+N"
2- Declare your function writing:
function [opt, fopt, histf] = ga(n, fitnessfct, decodefct, selectfct, stopeval)
% // function statements
end
3- Save the function file and name it as ga
4- Make sure setting the path of current directory to your working directory.
That is it..
Been trying (unsucessfully) to use 'which' to locate a .m file inside a package. For example, calling "which('Company.m')", when Company.m is inside a +Contents folder.
So if my current folder is C:\Users\Documents\Contents (path added to Matlab paths), "which('Company.m')" indicates no file found, but if my current folder is C:\Users***\Documents\Contents\ +Contents, then it will know the location.
Why is this? I thought that the 'which' command recursively searches through all subdirectories? Is there anyway to retrieve the path name of 'Company.m' without having to specifically source into that folder?
That should be:
which Contents.Company
If you dont know beforehand in which package it resides (or if its even in one), you could import them all:
import Contents.*
import OtherPackage.*
which -all Company
If you are still not satisfied, you could get a list of all top-level packages available, and search the methods they expose for the function you want:
%# warning: this might take more than a few seconds
p = meta.package.getAllPackages;
b = cellfun(#(pkg) ismember('Company',{pkg.FunctionList.Name}), p);
idx = find(b, 1, 'first');
p{idx}.Name
Apparently Matlab load loads the data from a .mat file into the variable that it was saved.
How can you load a single matrix from a .mat or binary file into an arbitrary variable?
Load it in to a struct and pop it out to your variable.
saved_name = 'varname_it_was_saved_as';
s = load('some_file.mat', saved_name);
my_new_variable = s.(saved_name);
I always use the struct forms of save and load for production code. It's cleaner because it doesn't dynamically fiddle with your workspace.
See help load for details.