I want to use MATLAB code in C++. I use Matcom (A tool used to covert M-files to C++) to add M-files to C++ current project. It compiles successfully but errors when running.
I created a matrix:
bit_in_char = uint16([...
0 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 1 2 2 3 2 3 ...
3 4 2 3 3 4 3 4 4 5 1 2 2 3 2 3 3 4 2 3 3 4 ...
3 4 4 5 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6 1 2 ...
2 3 2 3 3 4 2 3 3 4 3 4 4 5 2 3 3 4 3 4 4 5 ...
3 4 4 5 4 5 5 6 2 3 3 4 3 4 4 5 3 4 4 5 4 5 ...
5 6 3 4 4 5 4 5 5 6 4 5 5 6 5 6 6 7 1 2 2 3 ...
2 3 3 4 2 3 3 4 3 4 4 5 2 3 3 4 3 4 4 5 3 4 ...
4 5 4 5 5 6 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6 ...
3 4 4 5 4 5 5 6 4 5 5 6 5 6 6 7 2 3 3 4 3 4 ...
4 5 3 4 4 5 4 5 5 6 3 4 4 5 4 5 5 6 4 5 5 6 ...
5 6 6 7 3 4 4 5 4 5 5 6 4 5 5 6 5 6 6 7 4 5 ...
5 6 5 6 6 7 5 6 6 7 6 7 7 8]);
The code is running successful in MATLAB, but has error "uint6 is not yet implemented" in VC. Are data structures the same in MATLAB and VC?
The problem most likely is caused by VC6. That's a compiler from the previous century. Upgrade to something still supported, and it will probably work.
Use matlab corder in MATLAB 2012b.
Related
set student;
set group;
var assign{i in student, j in group} binary;
param pref{i in student, j in group};
maximize totalPref:
sum{i in student, j in group} pref[i,j]*assign[i,j];
subject to exactly_one_group {i in student}:
sum {j in group} assign[i,j] =1;
subject to min3{j in group}:
sum{i in student} assign[i,j]>=3;
subject to max4{j in group}:
sum{i in student} assign[i,j]<=4;
##########
data;
set group:= A ED EZ G H1 H2 RB SC;
set student:= Allen Black Chung Clark Conners Cumming Demming Eng Farmer Forest Goodman Harris Holmes Johnson Knorr Manheim Morris Nathan Neuman Patrick Rollins Schuman Silver Stein Stock Truman Wolman Young;
param pref:
A ED EZ G H1 H2 RB SC:=
Allen 1 3 4 7 7 5 2 6
Black 6 4 3 5 5 7 1
Chung 6 2 3 1 1 7 5 4
Clark 7 6 1 2 2 3 5 4
Conners 7 6 1 3 3 4 5 2
Cumming 6 7 4 2 2 3 5 1
Demming 2 5 4 6 6 1 3 7
Eng 4 7 2 1 1 6 3 5
Farmer 7 6 5 2 2 1 3 4
Forest 6 7 2 5 5 1 3 4
Goodman 7 6 2 4 4 5 1 3
Harris 4 7 5 3 3 1 2 6
Holmes 6 7 4 2 2 3 5 1
Johnson 7 2 4 6 6 5 3 1
Knorr 7 4 1 2 2 5 6 3
Manheim 4 7 2 1 1 3 6 5
Morris 7 5 4 6 6 3 1 2
Nathan 4 7 5 6 6 3 1 2
Neuman 7 5 4 6 6 3 1 2
Patrick 1 7 5 4 4 2 3 6
Rollins 6 2 3 1 1 7 5 4
Schuman 4 7 3 5 5 1 2 6
Silver 4 7 3 1 1 2 5 6
Stein 6 4 2 5 5 7 1 3
Stock 5 2 1 6 6 7 4 3
Truman 6 3 2 7 7 5 1 4
Wolman 6 7 4 2 2 3 5 1
Young 1 3 4 7 7 6 2 5;
Suppose that you are allowed to assign up to two groups to un-qualified students. How would you reformulate the problem and find the new solution, with preference still applying? * means un-qualified
param pref: A ED EZ G H1 H2 RB SC:= Allen 1 3 * 7 7 5 * 6 Black 6 * 3 5 5 * 1 3 Chung 6 2 3 1 * 7 5 * Clark * 6 1 * 2 3 5 4 Conners 7 6 1 3 3 * * 2
I have the following
and I would like to translate to an adjacency matrix.
This is how I did it
s=[1 1 2 2 2 3 3 4 4 4 5 5 6 7];
t=[2 3 4 5 3 5 6 5 7 8 6 8 7 8];
w=[3 5 4 7 4 9 8 3 11 8 3 9 8 7];
G=graph(s,t,w);
A=adjacency(G)
Could you please tell me if is it correct?
I'm using knnclassify to do a kNN classification in Matlab and it's working well. Now, I need to know the distances to the neighbors and it seems that knnsearch funcion gives me that.
The problem is the results are not the same. I am quite sure knnsearch is not working properly, but I don't know the reason.
This is my code:
k=1;
distance='euclidean';
rule='nearest';
%kNN classification
result = knnclassify(sample_matrix, training_matrix, label_matrix,k,distance,rule);
%showing which element is recognized and the distance to it
[recognition,distances] = knnsearch(training_matrix, sample_matrix,'k',k);
So, result and recognition should be the same, and then I can see the distances.
This is result:
4 1 1 2 4 1 1 4 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 2 3 3 3 3 3 3 4 4 4 4 4
4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9
And this is recognition:
3 1 1 2 3 1 1 3 1 1 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 3 2 2 4 3 3 4 3
4 4 3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 6 6 6 5 5 6 6 6
7 6 6 6 6 7 6 6 6 7 8 7 7 7 7 7 7 7 7 7
(They're supposed to be two vectors).
The desired result is
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4
4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8
8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9
So, result is almost well (good enough) and recognition is a disaster.
As you can see the beginning is much better than the end.
Anybody can help me??
Thank you very much.
For e.g., if [1,2,3,4,5,6] is a vector, then all possible combinations of 3 items at a time is
4 5 6
3 5 6
3 4 6
3 4 5
2 5 6
2 4 6
2 4 5
2 3 6
2 3 5
2 3 4
1 5 6
1 4 6
1 4 5
1 3 6
1 3 5
1 3 4
1 2 6
1 2 5
1 2 4
1 2 3
How do I find this in MATLAB?
Try this link. Basically you just need to type c = combnk(1:6,3). Hope it helps.
Edit: The difference between what I proposed and #nash 's combntns is the toolbox that the commands are in. combnk is in the Statistics Toolbox, while combntns is in the Mapping Toolbox.
>> combos = combntns([1 2 3 4 5 6], 3)
Output:
1 2 3
1 2 4
1 2 5
1 2 6
1 3 4
1 3 5
1 3 6
1 4 5
1 4 6
1 5 6
2 3 4
2 3 5
2 3 6
2 4 5
2 4 6
2 5 6
3 4 5
3 4 6
3 5 6
4 5 6
I use:
allCombos = nchoosek([1:n],k);
I prefer this, as nchoosek comes with Matlab, no toolbox needed.
I am trying to create a matrix that is 3 x n, with each of the columns being the same. What's the easiest way of achieving it? Concatenation?
After
n=7
x=[1;2;3]
it's either
repmat(x,[1 n])
or
x(:,ones(1,n))
(Octave can be considered as an open source/free version of MATLAB)
octave-3.0.3:2> rowvec = [1:10]
rowvec =
1 2 3 4 5 6 7 8 9 10
octave-3.0.3:3> [rowvec; rowvec; rowvec]
ans =
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
Use repmat if the number of rows is large.
octave-3.0.3:7> repmat(rowvec, 10, 1)
ans =
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
Use multiplication with a 1 x 3 matrix of ones
eg, x * [1 1 1]
Edit:
In Octave:
octave-3.0.3.exe:1> x = [1;2;3;4]
x =
1
2
3
4
octave-3.0.3.exe:5> x * [1 1 1]
ans =
1 1 1
2 2 2
3 3 3
4 4 4