LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

.mlv and .mat files

Hi,
I am running a code in a Mathscript node and saving some variables at the end of the execution in a file (.mlv).
I understand that these file format is exclusive to Mathscript, but is there someway I can convert this to a .mat file so that it can be stored in a database and used with MATLAB later whenever needed?

Any help or suggestions are appreciated.

Thanks,
Chintan
0 Kudos
Message 1 of 4
(7,584 Views)
Hello Chintan,

We do not have a mechanism to convert from .mlv to .mat.  An alternative is to use a different function to save your data.  Functions such as dlmwrite and csvwrite should do what you need, although you can only save one variable to each file.

Have you tried using LabVIEW MathScript to perform whatever offline analysis you are currently doing?  Did you encounter any problems?

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 2 of 4
(7,573 Views)
Hi Grant,
Thanks for your reply.
I have tried the data analysis offline. While saving it in .mlv it saves all the variables perfectly. I tried using csvwrite and dlmwrite as well, but they just write random number instead of the variables I specify in the syntax.
Here is the code I am using. The saving part at the bottom is what is bugging me. Everything else works fine. Please suggest another way to do this.
Thanks,
Chintan

data=-load(dataf);           %load decay data
head=load(headf);             %load header
laser = load(laserf);        

data_length=length(data);
mode=head(1);           %Single=0, Multi=1, Filter=2
tres=head(2)*10^9;      %resolution in ns

switch mode
    case 0
        lamb_num=1;
        lambdas=head(12); %lambda summary
        lambda_vec=head(13+lamb_num:end);   %vector with wavelengths
  
        dec_num=head(10);
        rep_num=head(11);
        flag=0;
    case 1
        Wini=head(9);           %first wavelength (nm)
        Wend=head(10);           %final wavelength (nm)
        Wstp=head(8) ;          %steps (nm)
        lambdas=[Wini Wstp Wend];       %lambda summary
        lambda_vec= head(14:end-1);        %vector with wavelengths
        lamb_num=head(11)/head(12);        %number of wavelengths measured
        dec_num=head(11);
        Wini=head(9);           %first wavelength (nm)
        Wend=head(10);           %final wavelength (nm)
        Wstp=head(8) ;          %steps (nm)
        rep_num=head(12);
        gain = head(7);
        flag=0;
    case 2
        dec_num=head(9);
        rep_num=head(7);
        filter_wheel_pos=head(8);
        center_wavelenghts=head(13:end);
       
        flag=1;
end

lim=[30/tres 100/tres];

trspec=data(lim(1):lim(2),:);                                       %truncate data
laser=laser(lim(1):lim(2),:);
trspec=trspec-ones(lim(2)-lim(1)+1,1)*mean(trspec(1:2/tres,:));     %detrend (substract mean of first 2 ns)
time_vec=[0:lim(2)-lim(1)]*tres;

stspec=trapz(trspec);

if flag==0
    save('Processed','mode','tres','dec_num','rep_num','lambda_vec','lambdas','trspec','stspec','time_vec','gain','laser');
end
if flag == 1
    save('Processed','mode','tres','dec_num','rep_num','trspec','stspec','time_vec','filter_wheel_pos','center_wavelenghts','fwhm');
end
0 Kudos
Message 3 of 4
(7,560 Views)
Hello Chintan,

It looks like there may be a few problems with the script you posted (or perhaps, there is more to the script that you didn't post).  For example, the "Processed" variable is not defined but you try to save it at the end.  Also, the "gain" variable that you save is only computed in case 1 of your switch statement.  However, flag is set to 0 in both case 0 and 1 of the switch statement meaning the line that saves the gain variable will be executed for both cases.  This could cause an undefined variable error.

As for your question, switching to csvwrite or dlmwrite is not just a replacement for the save function.  These functions only save one variable per file, so you would need to write something like
csvwrite('Processed.dat', Processed);
csvwrite('mode.dat', mode);
csvwrite('tres.dat', tres);

etc.

Since you are saving your data for later analysis, have you tried using LabVIEW MathScript for this?  This way, you could save your data in the default .mlv file and simply launch MathScript when you needed to analyze the data.  If you have tried this, were there any problems you encountered that made you want to save the data in a .mat file instead?

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 4 of 4
(7,539 Views)