Ver Mensaje Individual
  #11  
Antiguo 11-03-2009
rounin rounin is offline
Miembro
 
Registrado: sep 2005
Posts: 43
Reputación: 0
rounin Va por buen camino
No he entendido esencia de tu dificultad.
(Mi espanol es no muy bueno)

Sobre crear exe de m-file
Por ejemplo, tenemos test funcion en test.m.
(Matlab compiler puede compilar solo funciones)
Código:
 
%---------- test.m --------------
function test(arg1_str) 
  % puede ser sin argumentos

  k = eval(arg1_str);
  han = 128;
  N = 2048;
  rate = 1;
  for i = 1:N
      sample(i) = 3*rand() + sin(2.0*i)*sin(0.1*i);
  end;
  sample = sample .* k;
  [spectrum, freq] = psd(sample, N, rate, hanning(han), han/2, 'linear');
  dlmwrite('result.dat', [freq, spectrum], ' ');
Compilacion:
mcc -m -B sgl -I "C:\Program Files\MATLAB\R2007\toolbox\signal\signal" test.m
o simplemente
mcc -m test.m

Para posibilidad de ejecutar este exe-file en un ordernador sin Matlab,
necesitas instalar Matlab Run-Time.
(mglinstaller.exe en Matlab6.5, MCRInstaller.exe en Matlab2007R etc -
mira el Help)

De Delphi puedes ejecutar este exe-file y obtener resultados
por medio de archivo.

Código Delphi [-]
 
procedure TForm1.BExeClick(Sender: TObject);
const
  WAIT_MSEC = 60000;
var
  si: TStartupInfo;
  pi: TProcessInformation;
  Flags: Longint;
  ExitCode: DWORD;
  Ok: Boolean;
 
  procedure ReadResult;
  var f: TextFile;
      x, y: Double;
  begin
    PsdSeries.Clear;
    //AssignFile(f, 'C:\Program Files\MATLAB\R2007\work\result.dat');
    AssignFile(f, 'result.dat');
    Reset(f);
    try
      repeat
        ReadLn(f, x, y);
        PsdSeries.AddXY(x, y);
      until Eof(f);
    finally
      CloseFile(f);
    end;
  end;
 
begin
  FillChar(si, SizeOf(si), 0);
  si.cb := SizeOf(si);
  si.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
  si.wShowWindow := SW_HIDE; // SW_SHOW
  Flags := CREATE_DEFAULT_ERROR_MODE or NORMAL_PRIORITY_CLASS or CREATE_NEW_CONSOLE;
 
  // string argumento = '12' 
  if CreateProcess(nil, '"C:\Program Files\MATLAB\R2007\work\test.exe" "12"', nil, nil, True, Flags, nil, nil, si, pi) then
  begin
    CloseHandle(pi.hThread);
    try
      if WaitForSingleObject(pi.hProcess, WAIT_MSEC)= WAIT_OBJECT_0 then
      begin
        //GetExitCodeProcess(pi.hProcess, ExitCode);
        ReadResult;
      end;
    finally
      CloseHandle(pi.hProcess);
    end;
  end;
end;
Responder Con Cita