Thread: Matlab to C converting problems

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    4

    Matlab to C converting problems

    Hello!

    I have a little problem I'm completely new to C. I'm trying to translate a matlab program to C and having some problems.

    Firstly I have a while loop where the exit requirements is that a a difference between temperature between two iterations must be smaller the a set error.
    In matlab I do like this:

    Code:
    T_capt_out=[];
    n_iter=0;
    E=100;
    while E>0.0001
    
    n_iter=n_iter+1;
    
    calculating temp code...
    
    T_capt_out(n_iter)=T_calc
    
        if length(T_capt_out)>1
             E=abs(T_capt_out(end)-T_capt_out(end-1));
        end
    end
    How would i implement this in C since I can't make T_capt_out=[] array that I just fill up?

  2. #2
    Novice
    Join Date
    Jul 2009
    Posts
    568
    [Redacted on second thought]

    Consider allocating and extending the array dynamically, as you go. Look up malloca() and realloc().
    Last edited by msh; 05-11-2010 at 03:28 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 09-20-2009, 07:39 AM
  2. Convert Matlab Algebraic Sol to C compatible
    By Takeshi in forum C Programming
    Replies: 3
    Last Post: 01-08-2009, 06:35 PM
  3. MATLAB importing C libraries
    By chico1st in forum C Programming
    Replies: 1
    Last Post: 05-29-2008, 02:01 PM
  4. C/C++ and Matlab?
    By darkwalk in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2006, 03:00 AM
  5. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM