It is so strange that when I copy and paste the following matlab example
http://www.mathworks.co.jp/help/toolbox/stats/kmeans.html
to the work place and it says:
??? Error using ==> kmeans
Too many input arguments.
Anybody has the same problem?
#carlodsc is right.
Doing which kmeans, I can see that my kmeans function is located there:
/usr/local/MATLAB/R2011a/toolbox/stats/stats/kmeans.m
Since yours is located somewhere else, it means that you have another kmean function that is executed.
You should remove it from the path by doing:
rmpath ..\MATLAB\PT-MT\NetLab
Ok Oli.
Another or perhaps better solution is increasing the priority of
the path '...MATLAB/R2011a/toolbox/stats/stats' proportional to other paths containing kmeans. this can be done easily in the 'set path' window.
Related
I have a very simple MATLAB program for training and testing a regression tree, I use the same Data carsmall that is in the tutorial examples:
clear all
clc
close all
load carsmall
X = [Cylinders, Weight, Horsepower, Displacement];
Y = MPG;
tree = fitrtree(X,Y, 'PredictorNames',{'Cylinders', 'Weight', 'Horsepower', 'Displacement'},'ResponseName','MPG','MinLeaf',10);
Xtest=[6,4100,150,130];
MPGest = predict(tree, Xtest);
This gives as a result MPGest=14.9167
I want to know how the predict function is arriving at that value, usually to understand I go line by line inside the function. This one is very tricky because uses classes so I arrive at this line
node = findNode(this.Impl,X,this.DataSummary.CategoricalPredictors,subtrees);
and inside that function I arrive to
n = classreg.learning.treeutils.findNode(X,...
subtrees,this.PruneList,...
this.Children',iscat,...
this.CutVar,this.CutPoint,this.CutCategories,...
this.SurrCutFlip,this.SurrCutVar,...
this.SurrCutPoint,this.SurrCutCategories,...
verbose);
when I try to step in at this step it just give me n=10, how is MATLAB arriving at this number? for example, If I wanted to make my own program to calculate this number using the tree object as input without using predict?
Actually, the function you are looking for is defined into a MEX file. If you try to open it using the open function, you will get the following outcome:
open 'classreg.learning.treeutils.findNode'
Error using open (line 145) Cannot edit the MEX-file
'C:...\toolbox\stats\classreg+classreg+learning+treeutils\findNode.mexw64'
Unfortunately, MEX files are compiled from C++ sources into bytecode (better known as assembly language). There are many decompilers out there that you can use in order to rebuild the instructions compiled into the library (this is a nice starting point, if you want a fast overview), and the whole process is feasible especially because the file itself is quite small.
The code you will get back will not be the original source code, but something similar: variables will have a default and meaningless name, there will be pointers all over and it may also contain bugs due to a wrong reversing of some assembly instructions. This will be probably enough to let you understand what's going on, but you will not be able to follow the computations through a step by step debugging session in Matlab.
Now, the only question you have to answer to is: is this worth the effort?
I want to use fig2texPS to export plots from MATLAB to LaTeX. I copied the the script to D:\Eigene Dokumente\MATLAB\fig2TexPS and added this folder as a path in MATLAB. Unfortunately, I receive the following error:
>> fig2texPS()
Undefined function 'find' for input arguments of type 'matlab.graphics.chart.primitive.Line'.
Error in fig2texPS (line 526)
lsh = double(find(handle(lshandles),'-class','graph2d.lineseries')); % find plots
PS: I use a version of the script which was updated in order to work with pdtlatex (http://pastebin.com/xK6KxxBT) that I found in the MATLAB Central File Exchange. The same error also occurs when I use the original script.
This might not be the answer you are looking for, but there is the marvelous matlab2tikz that does the job of conversion of figures quite nicely, which you could use as an alternative to fig2texPS.
I also use the function fig2texPS.m and it works very well. It might be an answer for your question to use an older version of Matlab. I am using 2013b and it works. While I have tried this function with Matlab 2015a, I was getting the same error message.
I hope my answer helps you with your problems.
I have observed a strange behavior in running the same code in a Matlab function and in the command window. It's already described in How does scoping in Matlab work? , but I don't understand how I could solve my specific problem.
The code is the following:
exporteddata.m %File created by an external program
%to export data in Matlab format
surface = struct('vertices', [...]) ;
%I can't specify in the external program
%the name of the variable, it's always "surface"
My actual code is:
myfunction.m
function output = myfunction(input)
load(input);
n = size(surface.vertices);
....
When running
myfunction('exporteddata.m');
I get the following error:
??? No appropriate method, property, or field vertices for class hg.surface.
When running the same instructions from the command window or in debug mode, the code works well.
How can I specify in the function that I need the variable surface present in the workspace, not the Matlab function?
First of all, I must point out that surface is a built-in function in MATLAB, so overloading it is just... bad. Bad, bad, BAD!
Having said that, the MATLAB interpreter does a pretty good job at resolving variable names and usually tells them apart from function names correctly. So where's your problem, you ask?
I believe that you're using the wrong function: load is a function that loads data from MAT files into the workspace. It is not fit for m-files. By not executing "exportedata.m" properly, surface has never been created as a variable, so MATLAB identifies it as a function name. If you want to execute "exportedata.m", just type:
exportedata
and if you want to run the file with the filename stored in input, you can use run:
run(input)
By executing run(input) from within myfunction, surface should be created in myfunction's local scope, and it should work.
EDIT:
I've just tested it, and the interpreter still gets confused. so the issue of the variable name resolution remains. Here's a workaround:
function output = myfunction(input)
surface = 0; %// <-- Pay attention to this line
run(input);
n = size(surface.vertices);
Predefining surface allows the interpreter to identify it as a variable throughout your entire function. I've tried it and it works.
Ok, so this question is related to my ongoing task of getting text data categorized, you can refer to this question for more details on how I approached this problem.
I used the standard matlab function "nctool" (neural clustering tool) to get my inputs organized on a plane of 10x10 SOM nodes. I also got the output of this map (i.e. which of my inputs ended up on which node) saved in to the "output" variable in my workspace.
I would now like to get this data out and see if I can write another script. I'm aware of the 'save' and some of the export functions in MATLAB, however it seems that MATLAB does not support ascii export of this variable since it is a sparse matrix.
I am currently writing a script to get this thing exported out, however if someone already has a solution, please post. Otherwise I will do so after I finish testing it.
Update: I found a workaround to this fairly easily:
% convert a sparse matrix to full
output = full(output);
% output this to a file (excel)
xlswrite('test.csv',output);
I want to know how can this function(from MATLAB) resize the columns of an input image using weights an indices previously computed.
Which equations uses to do that?
resizeColumnsCore(double(in), weights', indices');
When I looked for a function called resizeColumnsCore in MATLAB 7.11.0 (R2010b) I didn't find anything. However, I did find a MEX-file by that name in MATLAB 7.8.0 (R2009a) in this subdirectory of the Image Processing Toolbox:
C:\Program Files\MATLAB\R2009a\toolbox\images\images\private\
I guess they've phased it out or replaced it with another function in newer MATLAB versions. Now, if you want to know what the MEX-file does, you need to look at the source code it is compiled from. Luckily, it appears that this source code resizeColumnsCore.cpp can be found in the following directory:
C:\Program Files\MATLAB\R2009a\toolbox\images\images\private\src\misc\
And you can look through that code to determine the algorithms used to resize the columns of an image given a set of weights and indices.
Now, if you want to know how these input arguments to resizeColumnsCore are computed, you'll have to look at the code of a function that calls it. I know of at least one function in the IPT that calls this function: IMRESIZE. If you type edit imresize at the command prompt it will open that function in the Editor, allowing you to look through the code so you can see how the arguments to resizeColumnsCore are created.
What I can tell you for R2009a is that there is a subfunction in the file imresize.m called contributions which computes the weights and indices that are ultimately passed as arguments to resizeColumnsCore. That is where you will want to start looking to determine what algorithms are used to compute these arguments.
Looks like this isn't a proprietary MATLAB function. Could we see some code or a link to the code?