MATLAB: Undefined function 'libsvmwrite' for input arguments of type 'char' - matlab

I'm trying to convert a CSV file to LIBSVM/SVMlight format. I found the following code to do it:
SPECTF = csvread('SPECTF.train'); % read a csv file
labels = SPECTF(:, 1); % labels from the 1st column
features = SPECTF(:, 2:end);
features_sparse = sparse(features); % features must be in a sparse matrix
libsvmwrite('SPECTFlibsvm.train', labels, features_sparse);
I used it on Octave on a specific file, and it worked properly.
However, when trying it on MATLAB, I received the error:
Undefined function 'libsvmwrite' for input arguments of type 'char'.
Neither "labels" nor "features_sparse" are chars... (they are doubles). Where is my error? Thanks!

The first argument for libsvmwrite is of type char ( the filename 'SPECTFlibsvm.train'). I think the problem is on the error message given by Matlab. The error message says that the function doesn't exist for input of type char, but most likely it should be that it doesn't exist at all (the message could maybe make sense if Matlab was designed as an OPP language).
Anyway, you simply don't have the libsvmwrite function in your path, or you somehow messed up the installation of the libsvm interface.

Probably you loaded only the source code, which is written in c. You need to compile it. Go to the matlab directory of libsvm and read the instructions.

Related

Error in MATLAB.Undefined function 'det' for input arguments of type 'embedded.fi'

I have already seen the link Error using fzero in Matlab: Undefined function or method 'det' for input arguments of type 'function_handle'
But I am unable to solye my problem with this link.I am working with fi object in MATLAB. I have one matrix T_1 (2 cross 2) which is conevrted into the fi(T_1,1,32,26,fimath), i.e 32 signed binary number and 26 is the positon of binary point. Now when I try to excute the follwing code
T = mat_G/(mat_sqrt_D)
T_1=fi(T./mat_E,1,32,26,fimath);
multiplier=1/(2*sqrt(det(var_oldS))*abs(det(T_1)));
follwing error appears
Undefined function 'det' for input arguments of type 'embedded.fi'.
So can anyone tell me how can i fix it.
P.S variable var_oldS, mat_G,mat_E, mat_qrt_D has the same fi object properties i.e fi(variable_name,1,32,26,fimath)
If you check the documentation for det, it says that the input must be single or double. Fixed point is probably not supported. As your matrix is of fixed size 4, it's simple to replace the function:
det2=#(M)M(1)*M(4)-M(2)*M(3)
Then use det2 instead of det.

Error regarding inlineeval in MATLAB

As part of a group project we have a system of 2 non linear differential equations and we have to draw the S=S(t) , I=I(t) graphic using the midpoint method.
And I'm getting the following error when trying to insert the matrix with the corresponding differential equations:
"Error in inline expression ==> matrix([[-(IS)/1000], [(IS)/1000 - (3*I)/10]])
Undefined function 'matrix' for input arguments of type 'double'.
Error in inline/subsref (line 23)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);"
The code I have done is the following:
syms I S
u=[S;I];
F=[-0.001*S*I;0.001*S*I-0.3*I];
F1=inline(char(F),'I','S');
h=100; %Valores aleatórios
T=100000;
ni=(T/h);
u0=[799;1];
f=zeros(1,2);
k=zeros(1,2);
i=1;
while i<=ni
f(1)=F1(u0(1));
f(2)=F1(u0(2));
dx=h*f;
k(1)=F1((u0(1)+h*(1/2)),(u0(2)+h*(1/2)));
k(2)=F1((u0(1)+h*(1/2)),(u0(2)+h*(1/2)));
u1=u0+h*k;
disp('i:'),disp(i)
disp('u= '),disp(u1)
u0=u1;
i=i+1;
end
I'm new to this so the algorithm it's very likely to be wrong but if someone could help me with that error I'd apreciate it. Thank you!
The problem that specifically creates the error is that you are putting two symbolic functions into a matrix and then calling char (which outputs matrix([[-(IS)/1000], [(IS)/1000 - (3*I)/10]]) rather than converting nicely to string).
The secondary problem is that you are trying to pass two functions simultaneously to inline. inline creates a single function from a string (and using anonymous functions instead of inline is preferred anyway). You cannot put multiple functions in it.
You don't need sym here. In fact, avoid it (more trouble than it's worth) if you don't need to manipulate the equations at all. A common method is to create a cell array:
F{1} = #(I,S) -0.001*S*I;
F{2} = #(I,S) 0.001*S*I-0.3*I;
You can then pass in I and S as so:
F{1}(500,500)
Note that both your functions include both I and S, so they are always necessary. Reconsider what you were expecting when passing only one variable like this: f(1)=F1(u0(1));, because that will also give an error.

Matlab Error: Undefined function 'knnclassify' for input arguments of type 'double'

I am trying to do knnclassify on test_data(10000X784), train_data(50000X784), train_label(50000X1) and k = 1
And I am calling this function as follows:
label = knnclassify(test_data,train_data,train_label,k);
Background:
Where train_label is numeric equivalent digit of the data given in train_data. I want to classify my test_data. The data in both the train and test are in random order, but the train_label totally corresponds with the data in the train_data.
In my friend's workstation it works fine, but in my laptop it gives this error:
Undefined function 'knnclassify' for input arguments of type 'double'.
What could be the reason for the issue and how to solve it? Do I need to install any package? If yes how?
This error means that the function cannot be found in matlab, so you might missing the required toolbox. Just as #schorsch said you need to install the Bioinformatics toolbox.
A way to find out if the function is available in Matlab is typing which knnclassify. The output will be the route where the function resides or 'knnclassify' not found. otherwise.

MATLAB uint8 data type variable save

does anyone know how to save an uint8 workspace variable to a txt file?
I tried using MATLAB save command:
save zipped.txt zipped -ascii
However, the command window displayed warning error:
Warning: Attempt to write an unsupported data type to an ASCII file.
Variable 'zipped' not written to file.
In order to write it, simply cast your values to double before writing it.
A=uint8([1 2 3])
toWrite=double(A)
save('test.txt','toWrite','-ASCII')
The reason uint8 can't be written is hidden in the format section of the save doc online, took myself a bit to find it.
The doc page is here: http://www.mathworks.com/help/matlab/ref/save.html
The 3rd line after the table in the format section (about halfway down the page) says:
Each variable must be a two-dimensional double or character array.
Alternatively, dlmwrite can write matrices of type uint8, as the other poster also mentioned, and I am sure the csv one will work too, but I haven't tested it myself.
Hopefully that will help you out, kinda annoying though! I think uint8 is used almost exclusively for images in MATLAB, but I am assuming writing the values as an image is not feasible in your situation.
have you considered other write-to-file options in Matlab?
How about dlmwrite?
Another option might be cvswrite.
For more information see this document.
Try the following:
%# a random matrix of type uint8
x = randi(255, [100,3], 'uint8');
%# build format string
frmt = repmat('%u,',1,size(x,2));
frmt = [frmt(1:end-1) '\n'];
%# write matrix to file in one go
f = fopen('out.txt','wt');
fprintf(f, frmt, x');
fclose(f);
The resulting file will be something like:
16,108,149
174,25,138
11,153,222
19,121,68
...
where each line corresponds to a matrix row.
Note that this is much faster than using dlmwrite which writes one row at a time

which format can I give to imstack2vectors Matlab function?

So I have imported RGB photo into my Matlab workspace. It says it has value: <200x200x3 uint8>. Meaning it has class uint8. And its name is: prettyPic. So when I try to do the following:
% Convert prettyPic to vector format using function imstack2vectors.
[prettyPic, L] = imstack2vectors(prettyPic);
I get the following error:
??? Undefined function or method 'imstack2vectors' for input
arguments of type 'uint8'.
I was searching google all around reading the Matlab help and even trying to give 'imstack2vectors' different types of variables only to find that none works.
So the question is what type of picture should I feed the 'imstack2vectors' with. And how can I convert the picture that I have to that format/class.
I am a begginer in Matlab so any help would be greatly appreciated!
??? Undefined function or method 'imstack2vectors' for input arguments of type 'uint8'.
Means that most likely, the function imstack2vectors does not exist on your Matlab path (i.e Matlab cannot find a function of this name).
Type which imstack2vectors to see whether Matlab can find it on the path. If it returns nothing, but you know where the function is on your hard drive, you can change directories in Matlab to where the function is located, and then run your command again.
In general, you may want to learn about adding functions to the Matlab path.