VL_SIFT - Undefined function or variable - matlab

I try to make use of VLFeat library. So, I've downloaded the package and run vl_setup script. But when I create a new script and type this code:
I = imread('imhog.jpg');
image(I) ;
I = single(rgb2gray(I)) ;
[f,d] = vl_sift(I) ;
perm = randperm(size(f,2)) ;
sel = perm(1:50) ;
h1 = vl_plotframe(f(:,sel)) ;
h2 = vl_plotframe(f(:,sel)) ;
set(h1,'color','k','linewidth',3) ;
set(h2,'color','y','linewidth',2) ;
h3 = vl_plotsiftdescriptor(d(:,sel),f(:,sel)) ;
set(h3,'color','g') ;
it gives such error:
vl_sift('imhog.jpg')
Undefined function or variable 'vl_sift'.

Related

Variable not defined

I wanted to run this line but unfortunately it throws an error. Any ideas?
Undefined function or variable mr.
Error in Playground (line 23)
X = min(mr);
j = 1;
for i = 1:(resolution1+1)
line(i) = m(a(1))*ab(i)+c;
end
for i = 1:(resolution1)
if or(or(line(i)>ab_y(i) & line(i+1)<ab_y1(i+1),line(i)<ab_y1(i)& line(i+1)>ab_y1(i+1)),line(i)==ab_y1(i))
mr(j) = ab1(i);
rk(j) = ab_y1(j);
j = j+1;
end
end
X = min(mr);
Y = max(mr);
Your condition:
or(or(line(i)>ab_y(i) & line(i+1)<ab_y1(i+1),line(i)<ab_y1(i)& line(i+1)>ab_y1(i+1)),line(i)==ab_y1(i))
returns always false, so the statements inside
mr(j)=ab1(i); rk(j)=ab_y1(j);
are never executed. Therefore variable mr does not exist.
Add an mr = []; statement before the loop to initialize the variable (and also revise your condition why it returns always false).

Getting a "... not an elaboration-time constant" ... but haven't I already defined that array?

In the code fragment below I'm getting this error:
Source info:
x.data[theword][thebyteH : thebyteL] =
$urandom_range(0,255) ;
'this' is not an elaboration-time constant. To correct the error you may
convert this const variable to a parameter or a localparam.
The geometry of the data record, just a memory, is declared in the definition_pkg. A data record object is created in the Base_txn and
I can access it directly like so:
x.data[0][7:0] = x.frameID ;
I don't know why am I getting an elaboration time error since all that is happening (I think) in for loop is that I'm indexing an already existing object.
Any suggestions, explanation, or solutions appreciated.
definition_pkg.svh
`define REC_DATAWIDTH 32
`define REC_ROWS 16
typedef bit[`REC_DATAWIDTH-1:0] DataRec [`REC_ROWS] ;
sequences.sv
class Base_txn extends uvm_sequence_item;
rand DataRec data;
...
class sequencethingy extends uvm_sequence#(Base_txn);
...
int byte4val ;
int theword ;
int thebyteH ;
int thebyteL ;
// -----------------------------------------------------------------------
function void build_S (ref Base_txn x);
...
x.data[0][7:0] = x.frameID ;
...
for (int i = 8 ; i <= (byte4val+8) ; i++) // byte8 is the location of S[0]
begin
theword = i/4 ;
thebyteL = 8*(i%4) ;
thebyteH = thebyteL + 7 ;
x.data[theword][thebyteH : thebyteL] = $urandom_range(0,255) ;
end
endfunction
...
task body();
Base_txn wd_tx;
...
build_S(wd_tx) ; // give the processor some data
Write this as
x.data[theword][thebyteL +:8] = $urandom_range(0,255) ;
See Indexing vectors and arrays with +:

How can I modify a variable and it's corresponding dimension in a netcdf

I am running an idealized experiment with a atmospheric model with output in the format of netcdf. But the netcdf file header does not describe the variable and and dimension clearly. for example :
netcdf qc3d {
dimensions:
Time = UNLIMITED ; // (1453 currently)
bottom_top = 45 ;
south_north = 32 ;
west_east = 12288 ;
variables:
float Time(Time) ;
Time:axis = "Time" ;
Time:long_name = "Time" ;
Time:standard_name = "Time" ;
Time:units = "minutes since 1900-01-01 " ;
double zc(bottom_top) ;
zc:axis = "Z" ;
zc:long_name = "vertical height of model layers, MSL" ;
zc:standard_name = "altitude" ;
zc:units = "m" ;
zc:positive = "up" ;
double yc(south_north) ;
yc:axis = "Y" ;
yc:long_name = "y-coordinate of grid cell centers in Cartesian system" ;
yc:units = "m" ;
double xc(west_east) ;
xc:axis = "X" ;
xc:long_name = "x-coordinate of grid cell centers in Cartesian system" ;
xc:units = "m" ;
float qc(Time, bottom_top, south_north, west_east) ;
qc:long_name = "cloud water mixing ratio" ;
qc:standard_name = "cloud_water_mixing" ;
qc:units = "kg kg-1" ;
qc:_FillValue = 9.96921e+36f ;
qc:missing_value = 9.96921e+36f ;
// global attributes:
:model_tag = "CSU VVM" ;
:references = "http://kiwi.atmos.colostate.edu/pubs/joon-hee-tech_report.pdf" ;
:contact = "jung#atmos.colostate.edu" ;
:institution = "Colorado State University" ;
:VVM_casename = "GATE_PHASE_III " ;
}
there are 4 dimensions, Time(Time), zc(bottom_top), yc(south_north), xc(west_east) and 5 variable in which first 4 variables should be the dimension of the fifth variable, so called qc. But it seems not. The dimension is just a series number index from 1 to 45, 32 ...whatever else.
I would like to calculate some variable which is the function of pressure. in the CDO the script is like this
cdo expr,"pottemp=temp*((100000/clev(temp))^0.287);" ifile pottemp.nc
(this code is from here)
but I just obtain a series of index like 1 ,2 ,3 ... not the real pressure level when I use this function, clev(qv).
So how can I rewrite the variable dimension like qc from
qc(Time, bottom_top, south_north, west_east) ;
to
qc(Time, zc, yc, xc) ;
I think it's possible for me to finish this in matlab, but I just don't want to open this dataset because it's size is too large... so I am trying to find some tools like ncks or cdo, but still failed to do this.
thanks a lot.
With NCO try
ncap2 -s 'pottemp=temp*((100000/zc)^0.287)' in.nc out.nc
ncap2 documentation
extending answer to cover additional question below:
first use ncap2 to explicitly set zc to the values in the ascii file:
ncap2 -s 'zc[$zc]={1.5,900,2500,3500}' in.nc out.nc
(assuming zc is size 4 dimension). then define pottemp based on that zc.

Getting error from: dlen = uint32(0) ;

I don't know why but I am getting this error:
Error in mr_lsbpex (line 3)
dlen = uint32(0) ;
Output argument "a" (and maybe others) not assigned during call to "E:\path\mr_lsbpex.m>mr_lsbpex"
I have tested "dlen = uint32(0) ;" in matlab enviorment (outside of this function) and everything was OK. Here is my code:
function a = mr_lsbpex ( r, p )
% extract from an array
dlen = uint32(0) ;
s = size (r) ;
rnd = rand (s(1),s(2)) ;
rd = 32 ;
rl = s(2) ;
for i=1:s(2)
if rnd(1,i)<rd/rl
d = bitget (round(r(1,i)/p),1);
dlen = bitset (dlen,rd,d);
rd = rd -1 ;
end
rl = rl -1 ;
end
if (dlen > 10000000 )
clear a ;
return ;
end
a = uint8(zeros(dlen,1)) ;
rd = double(dlen * 8) ;
rl = double(s(1)*s(2)-s(2)) ;
for i=2:s(1)
for j=1:s(2)
if rnd(i,j)<rd/rl
d = bitget (round(r(i,j)/p) ,1) ;
a = z_set_bit (a,rd,d) ;
rd = rd - 1 ;
end
rl = rl - 1 ;
end
end
Remember: a needs to be returned ALLWAYS!
The error is not in that specific line, but in the "whole" function itself.
Your problem is that Matlab thinks that a its not going to be created. And actually in some case it may not be created.
The following line in the beginning of your function should do the trick
a=0; % well, or a=NaN; or whatever you want to return
Additionally, don't clear a in if (dlen > 10000000 ).

Input argument "ip" is undefined Error

I am new in matlab I am trying to define a function and I keep getting this error
" input argument "ip" is undefined.
Error in ==> edge_mapping at 2
size_ip = size(ip(:,:,1)); "
here is my code
function[op1,op2,op3] = edge_mapping(ip)
size_ip = size(ip(:,:,1));
s=size_ip(1);
op1= cat(3,zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s));
op2= cat(3,zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s));
op3= cat(3,zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s),zeros(s));
for i = 1 : 10
op1(:,:,i)=edge(ip(:,:,i),'sobel');
op2(:,:,i)=edge(ip(:,:,i),'prewitt');
op3(:,:,i)=edge(ip(:,:,i),'canny');
end
function [op1, op2, op3] = edge_mapping(ip)
op1 = zeros(size(ip));
op2 = zeros(size(ip));
op3 = zeros(size(ip));
for i = 1 : size(ip, 3)
op1(:,:,i)=edge(ip(:,:,i),'sobel');
op2(:,:,i)=edge(ip(:,:,i),'prewitt');
op3(:,:,i)=edge(ip(:,:,i),'canny');
end
return
But I think it's better to write a simple function:
function op = edge_mapping(ip, edge_mode)
op = zeros(size(ip));
for i = 1 : size(ip, 3)
op(:,:,i)=edge(ip(:,:,i), edge_mode);
end
return
and then call it:
op_sobel = edge_mapping(ip, 'sobel');
op_prewitt = edge_mapping(ip, 'prewitt');
op_canny = edge_mapping(ip, 'canny');
This code is a function. It has to be save as m-file and run from MATLAB command line, script or another function as
[op1,op2,op3] = edge_mapping(ip);
where arguments ip, op1, op2, and op3 can have different names.
Make sure you have space after function keyword.
To avoid this error you can assign a default value for the input argument if it's undefined (not exist in the function's scope):
if ~exist(ip, 'var')
ip = []; %# or other default value
end