I wrote this code inside the M Blcok (one of Xilinx blockstes in Simulink):
function z= discorr(x,y)
t=zeros(12288,1);
i=zeros(12288,1);
k=zeros(12288,1);
i(4096:8191,1)=x(1:4096,2); %output of the image filter
t(4096:8191,1)=y(1:4096,2); %output of the tamplate filter
i=i';
z=A(1:4096,1);
for n=1:8191
k=zeros(12288,1);
k(n:n+4095,1)=t(4096:8191,1);
z(n,2)=i*k;
end
end
Its telling me:
Error("discreatcorr.m"): Syntax error: Lexical error at line 15, column 0. Encountered: after : "\';\r\nz=A(1:4096,1);\r\nfor n=1:8191\r\n k=zeros(12288,1);\r\n k(n:n+4095,1)=t(4096:8191,1);\r\n z(n,2)=i*k;\r\n end\r\nend\r\n"
Error("discreatcorr.m"): Syntax error: Lexical error at line 15, column 0. Encountered: after : "\';\r\nz=A(1:4096,1);\r\nfor n=1:8191\r\n k=zeros(12288,1);\r\n k(n:n+4095,1)=t(4096:8191,1);\r\n z(n,2)=i*k;\r\n end\r\nend\r\n"
Error occurred during "Block Configuration".
althogh there is nothing in line 15 in the code
it is giving an error at the end of the code
Any Ideas??
The problem is that your system misinterprets the ' symbol as string symbol. Replacing the line i=i'; by i=transp(i); should solve the problem.
Related
I have a very odd error with cvx/matlab.
I'd like to solve SDP problem to get dual variable. Here is my code.
addpath(<cvx_directory>)
cvx_setup
cvx_begin
variable r(n);
variable R(n,n) symmetric;
dual variable alpha;
dual variable pi;
minimize(trace(A0*R))
pi: trace(A1*R) <=0;
alpha: r== diag(R);
[R r;r' 1] == semidefinite(n+1);
cvx_end
A0,A1 are given.
When I write the above code in the script form it does not return any error.
But I should pass the value of n (the size of variable), thus I edited the above code in the function form (Add function [output] = sdp(n) at the first line) and then it returns error :
Undefined operator ':' for input arguments of type 'cvx'.
Error in pi: trace(A1*R) <=0;
If I move dual variable pi to right of the line (as like trace(A1*R)<=0 : pi)
then it returns the other error :
Too many output arguments
Error in alpha: r== diag(R);
What happen?
// I added cvx_setup in the code to make sure that cvx is installed
I have this code: http://pastebin.com/E70c4UYY
When running, I get the following error:
Error using Diffusivity.getParams
Too many output arguments.
Error in Diffusivity.D_BA (line 63)
[sigmaA, epsK_A] = Diffusivity.getParams(specieA);
Error in Diffusivity.D_Amix (line 95)
Dam = fractionsArray(j) / Diffusivity.D_BA(specieA, fractionsArrayNames_cellstr{j}, T, P);
I do not understand how it can give an error, since in the code, on line 63 and 64 I have specified that there are two outputs?
I fixed it by changing line 9 from [results] = getParams(specie) to [sigma, epsK] = getParams(specie) and then just deleting line 54.
I try to check if input argument is of specific type and throw error message like:
function test(input)
if ~ischar(input)
error('%s is invalid input type.', class(input));
end
end
But Matlab shows error message with backtrace-information:
>> test(1)
Error using test (line 3)
double is invalid input type.
How can I turn off the line Error using test (line 3)?
I'm looking for something similar to off backtrace with warning: warning off backtrace;.
I'm not sure you can. The closest I got was by defining my own error structure:
testerr.message = 'test';
testerr.identifier = '';
testerr.stack.file = '';
testerr.stack.name = 'Test Thing';
testerr.stack.line = 1;
error(testerr)
Which returns:
Error using Test Thing
test
As long as you keep the file field blank it will not display the line specified in the stack.
One potential workaround could be a combination of fprintf and return, courtesy of Undocumented MATLAB:
function test(input)
if ~ischar(input)
fprintf(2, '%s is invalid input type.\n', class(input));
return
end
end
Depending on where this check resides in your real function you might need to get creative with how it exits, since return only kicks you back to the invoking function. Probably have it output a True/False flag?
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 wanted your help in writing a program to convert fortran array (n, m) in a table (p, 3).
I tried with this program:
program Temp
implicit none
real,dimension (23250,27)::table
real::time
integer::i
integer::j
integer::wl
integer::al
i=1,23250
read(*,*) time(i),wl(i),(table(i,j),j=1,27)
j=1,27
alt(j)=j
write(*,*) time(i),alt(j),table(i,j)
continue
continue
endprogram Temp
but error messages are displayed as:
D:\Travaux de thèse\modeling\essay\essay.f90(9) : Error: Syntax error, found ',' when expecting one of: <END-OF-STATEMENT> ;
i=1,23250
-----^
D:\Travaux de thèse\modeling\essay\essay.f90(11) : Error: Syntax error, found ',' when expecting one of: <END-OF-STATEMENT> ;
j=1,27
----^
D:\Travaux de thèse\modeling\essay\essay.f90(10) : Error: Constants and expressions are invalid in read-only I/O lists. [TIME]
read(*,*) time(i),wl(i),(table(i,j),j=1,27)
----------^
D:\Travaux de thèse\modeling\essay\essay.f90(10) : Error: Constants and expressions are invalid in read-only I/O lists. [WL]
read(*,*) time(i),wl(i),(table(i,j),j=1,27)
------------------^
D:\Travaux de thèse\modeling\essay\essay.f90(12) : Error: This name has not been declared as an array. [ALT]
alt(j)=j
^
Error executing df.exe.
essay.exe - 5 error(s), 0 warning(s)
Can anyone can help me?
T
hanks you in advance.
from your example code alone it is a bit difficult to figure out where this code is going. Where is your array 'array' you mention in the question defined? If you want to loop over something, you need to use the 'do' statement[1]. Furthermore I would try to access the dimension of that array programmatically, so you don't have to hard code it. The following code snippet is not complete, but maybe it gets you going.
program Temp
implicit none
real,dimension (23250,27)::table
integer, dimension(2) :: table_shape
real::time
integer::i
integer::j
integer::wl
integer::al
table_shape = shape(table)
do i=1, table_shape(1)
read(*,*) time(i),wl(i),(table(i,j),j=1,27)
do j=1, table_shape(2)
alt(j)=j
write(*,*) time(i),al(j),table(i,j)
!continue
!continue
enddo
enddo
endprogram Temp
Best,
Max
[1] http://en.wikibooks.org/wiki/Fortran/Fortran_control