Converting MATLAB function to C++
Hi,
I need to convert the following MATLAB function into C++. I ad have some info on using the Matlab engine but I still can understand what it is doing....
function [Is] = ver_eq(I)
l = length(I); Is = [];
if l > 1,
for i=1:l-1,
aux = I(i);
auxI = I(i+1:end);
el = find(auxI == aux, 1);
if isempty(el),
Is = [Is,aux];
end;
end;
Is = [Is,I(end)];
else
Is = I;
end;
Re: Converting MATLAB function to C++
Well, I have no idea what and how MATLAB function do anything, but
what does this problem have to do with this Forum:
Quote:
Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.
AFAIK MATLAB has nothing to do with Windows GUI. Perhaps, you should ask your question in some MATLAB specific Forum?
Re: Converting MATLAB function to C++
Victor, sorry I am talkative, isn't matlab a C/C++'s brother? I think you hate the OPey for his wider development in even matlab, rich knowledge, so you say like that, he uses this forum to stimulate the matlab function, satisfactorily and the dumbest yell later throughout the community, one that is similar in C++. I guess.
Re: Converting MATLAB function to C++
Quote:
Originally Posted by
PumpoBee
Victor, sorry I am talkative, isn't matlab a C/C++'s brother?
This is not a MatLab forum -- that's the bottom line.
Regards,
Paul McKenzie
Re: Converting MATLAB function to C++
Code tags help.
Code:
function [Is] = ver_eq(I)
l = length(I); Is = [];
if l > 1,
for i=1:l-1,
aux = I(i);
auxI = I(i+1:end);
el = find(auxI == aux, 1);
if isempty(el),
Is = [Is,aux];
end;
end;
Is = [Is,I(end)];
else
Is = I;
end;
From what I can tell, this code appears to be finding all unique values in the vector I. I don't know why the matlab function unique() wasn't simply used.
In any event, the C++ approach would be to first sort the container using std::sort(), then apply std::unique(), then erase the redundant portion of the container.
Re: Converting MATLAB function to C++
Quote:
Originally Posted by
stunner08
Hi,
I need to convert the following MATLAB function into C++.
Instead of posting MATLAB code, why not tell us what you're trying to do?
Quote:
From what I can tell, this code appears to be finding all unique values in the vector
If Lindley is correct, why didn't you just state what you're trying to do? You would have gotten help much faster.
If it is the case, then this is how you should have introduced your topic on this forum:
Quote:
Hello,
I have a series of values, and need to remove all the duplicates from the series of values. Can anyone suggest what is the best way to do that in C++?
No mention of MATLAB, and it would have gotten you responses much more quickly.
Regards,
Paul McKenzie