I am trying to call Eviews (8, 32bit) from Matlab (2013a, 32bit), but without success so far. I used the following code in Matlab:
clear all; clc;
hm = actxserver('EViews.Manager.8')
hm = COM.Eviews_Manager
h = hm.GetApplication(0)
h = Interface.EViews_8.0_Type_Library.IApplication
h.invoke
h.Show()
h.Run('wfcreate comEV u 4')
h.Run('genr x = #obsid')
I get the following error:
>> h = hm.GetApplication(0)
No appropriate method, property, or field GetApplication for class
COM.EViews_Manager_8.
Could anyone please help? Thanks in advance.
At the very least, you could write your program in EViews and then call it from Matlab* using the shell:
system(['"C:\Program Files\EViews 9\EViews9_x64.exe" "C:\Users\me\Documents\foo.prg"'])
*or Stata, R, Python, VBA, etc.
The line of code
h = Interface.EViews_8.0_Type_Library.IApplication
is not a command, is the output from the above line of your code
(h = hm.GetApplication(0)).
Just remove it from your script. I think this is the problem.
Related
i have a function
function[a,b,c] = segmentimage(image)
i am not able to give the image 'bird.png' to this function.
i get an error if i write
segmentimage('bird.png')
as
Error: File: segmentimage.m Line 27 Column: 66
if i declare
image= imread(bird.png)
before the function declaration, then also i am getting an error
Function definitions are not permitted at the prompt or in scripts.
please help. thanks in advance
In option 2 I think you're doing something like this in your script,
image= imread(bird.png)
function[a,b,c] = segmentimage(image)
First of all, you should have
image = imread('bird.png');
and you should not declare anything in the function script, so, erase the first line.
it should be,
function[a,b,c] = segmentimage(image)
%your code here,
im = imread(image);
%a = ...
%b = ...
%c = ...
end
then you can call your function in another script,
[a, b, c] = segmentimage('bird.png');
About the first error, you have to post some code, especially the line in which the error occurs so we can help.
I need to substitute a value for s in a transfer function. For example:
G(s)= 1/ (s+3)
I need to substitute
s = -2.118 +2.221j
What code should I use for this?
PS: Unfortunately, I only have control system toolbox in MATLAB.
What's wrong with saving m-file with
function g = transferFun( s )
g = 1 ./ ( s + 3 )
And then calling the function
>> transferFun( -2.118 + 2.221*j )
As shai mentioned you can simply create an m file with the function.
However, if you are just doing some quick calculations here is a way to just do it on the command line. You can define an anonymous function like this:
G = #(s) 1/(s+3)
Now you can simply call it like this:
G(-2.118 +2.221j)
Note that Matlab is case sensitive.
Here is my code:
function [im,sindx,end1]=alln(im,i,j,secret,sindx,end1)
slen=length(secret);
p=im(i,j);
neigh= [im(i-1,j) im(i+1,j) im(i,j-1) im(i,j+1) im(i-1,j-1) im(i+1,j-1) im(i-1,j+1) im(i+1,j+1)];
minpix = min (neigh)
maxpix = max (neigh)
if minpix < p < maxpix
lowlim = minpix+1;
highlim = maxpix-1;
range = highlim-lowlim+1;
nbits=floor(log2(abs(range)));
if sindx+nbits-1>slen
end1=1;
return
end
for k=1:nbits
bin(k)=secret(sindx+k-1);
end
b = bin2dec(bin);
newvalue1 = abs (minpix + b);
newvalue2 = abs (maxpix - b);
if abs(p-newvalue1)<= abs(p-newvalue2)
im(i,j) = newvalue1;
else
im(i,j) = newvalue2;
end
sindx=sindx+nbits;
end
end
My main program calls this function. When I run the program, I get the following error message:
??? Undefined function or variable "bin".
Error in ==> alln at 34
b = bin2dec(bin);
I know there are many experts for whom this is not a problem at all. I am new to MATLAB. Please guys, show me the way, which type of modification in the code can overcome this problem?
First of all, are there some lines missing from the file? Perhaps you've stripped some comments from the top? Because the error message says that
b = bin2dec(bin);
is line 34, but it's line 22 in the code you present.
OK, that aside...
The error message says that 'bin' isn't defined, but I see that it's being set on the line...
bin(k)=secret(sindx+k-1);
That suggests to me that THAT line isn't being run.
I see that that bin = ... line is inside of a 'for' loop, so I suspect that the for loop is run zero times, meaning that 'bin' never gets defined. What is nbits? Is it 1, or perhaps less than 1? THAT would prevent the loop from running at all.
Try removing the semicolon from the end of the
nbits=floor(log2(abs(range)));
line and run your code again.
Leaving off the semicolon will force the value of nbits to be printed in the Command Window. I bet you'll find that it's 1 or less. If that's the case, then start looking at HOW nbits is calculated, and I bet you'll find the problem.
At what input arguments to the function alln, are you getting the error?
Lets suppose that nbits is 0, then the following loop will not run:
for k=1:nbits
bin(k)=secret(sindx+k-1);
end
So, bin will be undefined. So, the error happens. This is one of the cases where the error can happen. There are many such possible cases.
I stumbled across this problem while working with Jacket.
I use a compiled function (compiled with gcompile) within a gfor loop. This is meant to be supported as far as I know: http://wiki.accelereyes.com/wiki/index.php/GCOMPILE
But I observed that while the uncompiled function delivers the correct results, the compiled function gives the same output for all the gfor-iterations:
%================
% function[C] = test(A,B)
% C = A+B;
% end
%================
testing = gcompile('test.m');
A = gdouble(1:1:10);
B = gdouble(2:2:20);
C1 = gzeros(10,1);
C2 = gzeros(10,1);
gfor l=1:10
C1(l) = test(A(l),B(l));
C2(l) = testing(A(l),B(l));
gend
The output is:
C1 = [ 3,6,9,12,15,18,21,24,27,30]
(correct result)
C2 = [ 3,3,3,3,3,3,3,3,3,3]
Can you verify/rebut my results?
What am I doing wrong?
Cheers,
Angela
I was able to reproduce this behavior by running Jacket on MATLAB. It appears that gcompile does not work over GFOR as it should, and the documentation was in error. Sorry about that.
Assume I have the function:
function name_the_paramlist(varargin)
% Print out varargin exactly how it is called as a string
Basically what I want it to do is, calling:
name_the_paramlist({'x', x}, y, 1, 'hello', [1, 2; 3, 4])
should print to the screen the string:
'{''x'', x}, y, 1, ''hello'', [1, 2; 3, 4]}'
Any suggestion?
ETA: The reason I want something like this is to hopefully resolve this question:
Matlab - how to create a subclass of dataset class keeping the dataset parameter constructor
Well, if you type this function call in a command line or run with F9 (so it get saved in the history) you can read the history.m file and get the last command as a string.
fid = fopen(fullfile(prefdir,'history.m'),'rt');
while ~feof(fid)
lastcmd = fgetl(fid);
end
fclose(fid);
Then get the argument part:
arg_str = regexp(lastcmd, '\w+\((.+)\)','tokens','once');
arg_str = strrep(arg_str{:},'''','''''');
UPDATE:
Another idea. If you call this function from another script or function (m-file) you can use DBSTACK to return the m-file name and the current line number:
SI = dbstack;
filename = SI(end).file;
lineNo = SI(end).line;
Then you can follow similar technique as in the first solution to read that line from the m-file and get argument part.
In opposite to the first solution this won't work if run from command line or editor cell mode.