-
September 18th, 2011, 10:04 AM
#1
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;
-
September 18th, 2011, 11:38 AM
#2
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:
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?
Victor Nijegorodov
-
September 19th, 2011, 01:18 AM
#3
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.
Last edited by PumpoBee; September 19th, 2011 at 01:20 AM.
Pumpobee is prolounced as mumbolee
-
September 19th, 2011, 04:58 AM
#4
Re: Converting MATLAB function to C++
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
-
September 19th, 2011, 10:38 AM
#5
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.
-
September 19th, 2011, 10:49 AM
#6
Re: Converting MATLAB function to C++
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?
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:
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|