CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2011
    Posts
    10

    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;

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  3. #3
    Join Date
    Jun 2006
    Location
    Chile
    Posts
    13

    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

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Converting MATLAB function to C++

    Quote Originally Posted by PumpoBee View Post
    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

  5. #5
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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.

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Converting MATLAB function to C++

    Quote Originally Posted by stunner08 View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured