Command line error in function call - matlab

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..

Related

Is it possible to call a script from within another script in Octave?

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');

What is the full command for gdal_calc in ipython?

I've been trying to use raster calculation in ipython for a tif file I have uploaded, but I'm unable to find the whole code for the function. I keep finding examples such as below, but am unsure how to use this.
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
I then tried another process by assigning sections, however this still doesn't work (code below)
a = '/iPythonData/cstone/prec_7.tif'
outfile = '/iPythonData/cstone/prec_result.tif'
expr = 'A<125'
gdal_calc.py -A=a --outfile=outfile --calc='expr' --NoDataValue=0
It keeps coming up with can't assign to operator. Can someone please help with the whole code.
Looking at the source code for gdal_calc.py, the file is only about 300 lines. Here is a link to that file.
https://raw.githubusercontent.com/OSGeo/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py
The punchline is that they just create an OptionParser object in main and pass it to the doit() method (Line 63). You could generate the same OptionParser instance based on the same arguments you pass to it via the command-line and call their doit method directly.
That said, a system call is perfectly valid per #thomas-k. This is only if you really want to stay in the Python environment.

how i can resolve error of paddedsize in matlab?

Undefined function or method 'paddedsize' for input arguments of type 'double'
how i can resolve this.
f = imread('cameraman.tif');
PQ=paddedsize(size(f));
F=fft2(f,PQ(1),PQ(2));
sig=40;
H=lpfilter('ideal',PQ(1),PQ(2),sig);
imshow(fftshift(H),[ ]);
G=H.*F;
g=real(ifft2(G));
g=g(1:size(f,1),1:size(f,2));
figure;
imshow(g,[ ]);
paddedsize is not a MATLAB builtin or library function. Presumably this comes from some third-party library you should try and find.
'paddedsize' is a function available on the Matlab File Exchange Here. In order to use the function you will need to download the m-file into your working directory or add the file location to your path.

Get list of object defined in base worspace MATLAB

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');

Windbg: Creating log of function entry and exit

I wish to create log of function entry and exit for my code. I am using the following command in WinDbg-
Function name and the return value
bm <module_name>!* "kcL1;.echotime;gu;r eax;.echotime;gc;"
Now I wish to do this for all the modules of the function but I don't want to write the code again for each module. Is there some way to specify bm to read module names from a file which I create using "lm" and set breakpoint for each module or something even more simple.
Also, how can I specify bm to not print the output on the screen? I am using a log file.
Sometimes I don't see the time for call exit. What can be the reason for this? How can I correct it?
you can use !for_each_module
You will not see call exit time if another breakpoint is hit (in another thread, or if the funciton calls other functions that have breakpoints)