Matlab file in MatlabScript or MathScript
Heloo
I need help in for loop which i impliment in Matlab
for i=1:16:256 %% where 16 is my jump and 256 is my total iterations
i=out; % out is some variable
end
when i write this Script in MathScript or MatlabScript and try to get the output of variable "out" it gives me only the last value which is 244(last value).I have changed the data type to "DBL". Also tryed to read "out" as array but only last value is comming. while i am interested in values like 1,17,33,49,65. . . How will i get these values as output in one by one iteration.ALso For loop of Labview 8.5 which i am using give the last value.
Regards
Madd
Hi Madd
When using the Mathscript node, you need to be exact with the datatype you output. In your case, you need to right-click on
the output node and Choose Data Type > 1-d array> I32
as you want to output an one dimensional array of integers. You don't need to do the same for the inputs, LabVIEW figures the datatype automatically
as it is usually a direct wire from a control and not a result of compiled text code.
KostasB
NI UK
Message Edited by KostasB on 02-13-2008 03:26 AM
Attachments:
mathscript_array.PNG 14 KB
Similar Messages
-
So, I search the binary matlab file format('*.mat').
Title:
Moving Data Between MATLAB® and LabVIEW
Problem:
How can I share data between LabVIEW and the MATLAB environment?
Solution:
MATLAB users can move data between the
MATLAB environment and LabVIEW, you have several options. Prior to
LabVIEW 5.1, the only way to transfer data between these two
environments was to use the Save and Load functions. Those are discussed herein.
Beginning
in LabVIEW 8.0, MathScipt was introduced. MathScript is an integrated
part of LabVIEW that you can use to combine intuitive graphical
dataflow programming with math-oriented textual programming. See the
attached links below for more information on MathScript.
Beginning
in LabVIEW 5.1, the MATLAB script node was introduced into the LabVIEW
programming environment. The MATLAB script node makes ActiveX calls to
the MATLAB software from within LabVIEW. This requires that both MATLAB
be installed on the same machine and that a valid license is obtained.
More information on the MATLAB script node can be found in the attached
KB's.
For all versions of LabVIEW, this data transfer can be
performed by saving the data in a file using the MATLAB software and
reading it directly from LabVIEW, or vice versa. In the MATLAB
environment, the command "save" allows you to save the data in
binary format (*.mat) or ASCII format. You also have an option of
saving it in ASCII format using a tab delimiter between data points and
the command "load" allows you to read in the data.
ASCII Format
Complete the following steps to import or export data between LabVIEW and the MATLAB environment using an ASCII file format.
From the MATLAB environment to LabVIEW
To save a vector or a matrix X in tab-delimited ASCII format, enter the following in the command window or m-script file in the MATLAB environment:
>>SAVE filename X -ascii -double -tabs
This creates a file named filename containing data X in tab-delimited ASCII format.
Import the file into LabVIEW using the Read From Spreadsheet File VI located on the Functions»File I/O palette.
From LabVIEW to the MATLAB environment
To export a matrix X from LabVIEW to the MATLAB environment, first save the data in ASCII format in LabVIEW using the Write To Spreadsheet File VI on the Functions » File I/O palette.
Enter the following in the command window of the MATLAB environment, or in the m-script file:
>> LOAD filename
This reads the data into the MATLAB environment.
Binary Format
Complete the following steps to import or export data between LabVIEW and the MATLAB environment.
From the MATLAB environment to LabVIEW
As mentioned above, LabVIEW does not save multiple variables to one
data with extra manipulation, and will not be discussed here.
Therefore, the only way of sending the data from the MATLAB environment
to LabVIEW without tampering with the MAT binary file structure is
using the ASCII format. Also, please bear in mind that you need to have
one file for one variable.
From LabVIEW to the MATLAB environment
Because
the MATLAB software saves data in its own binary format, the "MAT"
file, binary LabVIEW data must be converted to this format prior to
transferring the data. The attached examples can be used to save
LabVIEW data in the MATLAB software format. The convenience of the .MAT
file format is that more than one variable can be saved in the same
file. The example shows saving seven variables to .MAT format; the
example can be modified for any number of variables.
Once this data is saved from LabVIEW, it can be read into the MATLAB environment, using the following command:
>>LOAD filename
The Who
command can then be used to display all the seven variable names, and
you can display the content of them by entering the variable names at
the command prompt as usual.
MATLAB® is a
registered trademark of The MathWorks, Inc. Other product and company
names listed are trademarks and trade names of their respective
companies.
| Michael K | Project Manager | LabVIEW R&D | National Instruments | -
Calling a .m file from inside a mathscript node
hello all i am hoping someone can help me out, I am in the process of converting our version 7.11 matlab node vi's to mathscript (I hope) AND I HAVE RUN INTO AN ISSUE. we have a very simple matlab script that bundled the data and sent it to another matlab sub routine. when i copy this script over to mathscript I get the following eror: Unknown symbol on line 13: Pre_Process_Function_Pulse. Is there a way I can call and run these subroutines from the mathscript node? Do i need to convert the sub routines into a mathscript file? or do i just need to change the syntax for my call? bmp of the offending line in mathscript attached. please forgive if this is an easy question, I am not really a matlab programmer, the files that we are running are provided from elsewhere, and i get to integrate them any and all help is always appreciated thanks Chris
Attachments:
mathscript.JPG 51 KBHello again,
Ok I am still having issues running the matlab script in mathscript. I have gone back to the original scripts with all the nested sup routines. and the mathscript code is just a call to the first .m file subroutine. but for some reason mathscript will not recognize the function call as a call? I recreated the original matlab node in a sequence, so the matlab node runs (successfully) and then the next sequence is the identical call in mathscript. I have set the path in mathscript to the directory where all the .m files are located. The pre-process_function_pulse .m file sequentially calls 6 very small .m subroutine files. all are located in the same directory. and this directory is the only one listed under path and working directory in Mathscript preferences. Additionally from the last suggestions all traces of the original japanese comments have been deleted from all the .m files. The inputs and outputs are the same for the matlab and mathscript nodes. so i am basically at a loss here.
Any and all help will be greatly appreciated.
thank you
Chris
Attachments:
mathscript.doc 138 KB -
I wish to convert my Matlab files into .dll's so that I can use them in LabVIEW. I am using 'mcc' and 'mbuild' of Matlab to convert my .m files into .c and .dll.
When I try to run the .dll's in LabVIEW, I get an error message in a modal window stating some required .dll or procedure is not found.
How should I resolve this issue. Should I add any other Matlab .dll's in course of making my .dll?
Please help in solving this issue... Thankyou very much.KJV wrote in message news:<[email protected]>...
> When I run the matlab generated dll, it is stating 'matllb.dll not
> found'. Is it that I should set the path for matlab\bin to include
> all the dll's before I compile? When I make dll from C, it works fine
> in LabVIEW. The problem is from .m to .dll. The problem also arises
> when I convert my .m to .exe. The same error of 'matllb.dll not
> found' comes over. Should I change my matlab compiler options or
> something else? Please help me?
I have the same question,I don't know how to use the matlab DLL file in labview,
I hope someone can descripe the procedure in detail. -
How to convert a matlab file into VHDL thro LABVIEW?
Hi Friends,
I am having one MATLAB file. I need ti convert it into VHDL compatible domain thro LABVIEW? How to do this?
Please find the attached matlab code file in txt format.
Attachments:
Golden.doc 25 KBYou kind of lost me here. You have Matlab code. You want to convert it to VHDL. You want to use LabVIEW to do this.
Why?
Have you tried Google? -
A colleague of mine has made a Matlab .m file that I should call in from LabVIEW. I have imported the function into a Matlab script node. I haven installed Matlab on my PC and therefore i get a licence error. Before I ask my boss for a matlab licence i will ask this forum if there is another way. The Matlab function is still under development and will change a number of times. I could be nice if I didn't have to import the function every time the .m file changes
1. Could I use a MathScript node instead? Or is there another way for importing or calling that function without a Matlab Licence?
2. Is it possible to dynamically call the Matlab Script node/ MathScript node eg via a propertynode or another method instead of importing the function?I know the Model Interface Toolkit has some options for Matlab but I think that is only for compiled Matlab models.
http://sine.ni.com/nips/cds/view/p/lang/en/nid/211815
Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously. -
Learning how to use C++ with Matlab files
Hi guys!
I'm Ph.D student who needs to run thousands of mathematical simulations. Actually I'm working in MatLab, but due the massive quantity of simulations, I decided to make some tests in C++ in order to improve the time of the computations.
Well the thing is that all my data it's in mat files (Matlab filetype) and i tried three things for access them:
Use the library <fstream> but i found extremely complicated, specially with double numbers. (In fact i have to convert all my data to a text raw file)
Use the native API of C++ from Matlab, but i get the error
Warning: You are using gcc version "4.5.2". The version
currently supported with MEX is "4.3.4".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
and until now i don't know how to resolve it.
Finally i found one library http://sourceforge.net/projects/matio/ which in theory can handle mat files in C++ but I haven't could make it work in this test example http://na-wiki.csc.kth.se/mediawiki/index.php/MatIO:
#include <matio.h>
int main(void)
const double a[5] = {43.5, 5432.434, 3.32, 0.0001, 88834.0};
mat_t *mat;
matvar_t *matvar;
int dims[2] = {1,5};
mat = Mat_Open("simple.mat",MAT_ACC_RDWR);
if(mat)
matvar = Mat_VarCreate("vec1",MAT_C_DOUBLE,MAT_T_DOUBLE,2,dims,a,0);
Mat_VarWrite( mat, matvar, 0);
Mat_VarFree(matvar);
Mat_Close(mat);
else
return 1;
return 0;
because i get this:
/home/mikesol/projects/test/build> make
Scanning dependencies of target test
[100%] Building CXX object CMakeFiles/test.dir/main.cpp.o
/home/mikesol/projects/test/main.cpp: In function ‘int main()’:
/home/mikesol/projects/test/main.cpp:16:73: error: invalid conversion from ‘const void*’ to ‘void*’
/home/mikesol/projects/test/main.cpp:16:73: error: initializing argument 6 of ‘matvar_t* Mat_VarCreate(const char*, int, int, int, int*, void*, int)’
make[2]: *** [CMakeFiles/test.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***
i'm not so good in C++ to improve the code or know what is wrong. I'm sorry for that.
Summarizing: I'm stuck, so any help will be welcome.
Thanks in advance.thanks to all,
@ngoonee: I'm going to try the solution described in your post https://bbs.archlinux.org/viewtopic.php?id=86809.
@tavianator: Thanks for the solution, but now there are some "undefined reference" in the compilation
/home/mikesol/projects/test/build> make
[100%] Building CXX object CMakeFiles/test.dir/main.cpp.o
Linking CXX executable test
CMakeFiles/test.dir/main.cpp.o: In function `main':
/home/mikesol/projects/test/main.cpp:14: undefined reference to `Mat_Open'
/home/mikesol/projects/test/main.cpp:18: undefined reference to `Mat_VarCreate'
/home/mikesol/projects/test/main.cpp:19: undefined reference to `Mat_VarWrite'
/home/mikesol/projects/test/main.cpp:21: undefined reference to `Mat_VarFree'
/home/mikesol/projects/test/main.cpp:22: undefined reference to `Mat_Close'
collect2: ld returned 1 exit status
make[2]: *** [test] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***
I will return later to work in that. Thanks to all. -
Reading a mat (MATLAB) file
Hello,
does anyone has an example in CVI or any pointers on how to read a .mat file?
Thanks,
GregI never used Matlab but a search on the forum returns several threads that you may want to read; this one seems the most relevant to me.
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
Reading Large Matlab files into LabVIEW
Hi All,
I am using the 'Open Data Storage [MATLAB] block to read data from a mat file into MATLAB. The data is very large (in the order of millions). When I try to run my vi which is relatively simple to read in and manipulate the data, my LabVIEW said it does not have enough memory. Is there any way to around this problem without physically increasing computer memory.
Thanks in advance for any help and assistance.
ChrisHi Chris,
Did the 'not enough memory' happen on 'Open Data Storage' or 'Read Data' ?
If it happened on the 'Read Data', you might want to try specifying 'index/count' inputs of the 'Read Data' to read channel values chunk by chunk.
Best Regards,
Mavis -
In my LabView program, I want to execute a Matlab scrtipt. Part of the Matlab script loads another file. The error I get in LabView is 1050 ('Cannot open file'). The file is saved in the same directory as the LabView program file. What is the problem?
After reading some other discussions, I found the problem. In case anyone was wondering, the matlab directory needed to be changed to the labView directory.
-
Flash Player downloads as matlab file won't install
Whenever I try and update my flash player to the newest version it downloads as a .mdlp file and will not open in any program but matlab. Id imagine this is a somewhat unique issue and Adobe gives no way to contact them directly. Any help would be greatly appreciated I have tried uninstalling adobe flash player but once uninstalled it downloads the whole software package as a .mdlp that only opens with matlab otherwise the file generates an error stating that it cannot be opened.
Tried it doesn't work. Thats the file after a clean uninstall reboot and attempted reinstall. No clue what to do with it.
-
Logging data in a file using Labview VIs vs. Mathscript functions.
Hello,
I'm working on a data logger at 200 Hz frequency. I wanted to log the data to a file after eace sample received. When I used (fopen,fprintf,....) on Mathscript, the Labview started to log the data at a slower rate. I then used the Labview file VIs and it is working fine up till now.
My questions are as follows:
1- Are the file functions in the Mathscript slower than the Labview VIs ?
2- Is saving the data to a file after each sample is received a good idea or is there a better idea ? I just don't want to keep the data in the memory and after all the data is logged, I flush them to a file ... because, it seems that the PC will run out of memory.
Thank you,
Walidwfarid wrote:
Hello,
I'm working on a data logger at 200 Hz frequency. I wanted to log the data to a file after eace sample received. When I used (fopen,fprintf,....) on Mathscript, the Labview started to log the data at a slower rate. I then used the Labview file VIs and it is working fine up till now.
My questions are as follows:
1- Are the file functions in the Mathscript slower than the Labview VIs ?
Yes. That's because you're going through another layer of software. Why were you trying to use MathScript to log data to file in the first place? Are you a Matlab "aficionado"?
2- Is saving the data to a file after each sample is received a good idea or is there a better idea ? I just don't want to keep the data in the memory and after all the data is logged, I flush them to a file ... because, it seems that the PC will run out of memory.
It doesn't make sense to save data after each sample. File I/O is an expensive operation in terms of time, and you have the operating system to deal with, so while you may be able to keep up the rate for some time, eventually it will be thrown off. You can do as suggested which is to wait until you have a certain amount and then write that to file, or you can set up a producer-consumer or master-slave architecture. Let one process/loop collect the data and put into a buffer, like a queue, and the other process/loop can stream it to disk at a more reasonable rate. You just have to make sure the buffer is large enough so that if the file I/O gets hung up you won't reach the buffer's limit. -
Help needed Importing a string from labview into matlab for file opening
Hello,
I am using labview to allow the user to pick the file to open via the
open labview measurement file block. Then I take the filename and
convert it from a path to a string and try to import it into my matlab
script which I use dlmread() to open my data file. However the
datafile does not open. I was wondering if anyone would help me with
this method?
Thank you,Hi Nicole,
Are you using the Matlab Script Node or the MathScript Node? I know that dlmread is not currently implement with MathScript (although R&D is looking at implementing further features for future versions of LabVIEW). Also, I'm not sure which VI you are using to get the file path because there isn't an "Open LabVIEW Measurement File" VI. There are Read & Write LVM and a simple Open\Create\Replace File VI--are you using one of these? If you are using the Open File VI, Matlab may be unable to read from the file because it is already locked for editing by LabVIEW.
I hope this helps!
Megan B.
National Instruments -
I would like to run Matlab mex file in Labview - how to do this?
Hello
In order to run Labview without Matlab beeing installed I have to compile the matlab files, right? So I also want to run those files in Labiew, and I do not know how. Anybody can help.
Thanks a lot
kind regards
PawelPawel,
You can create a DLL in Matlab. To compile this DLL you should use both LabVIEW and Matlab typedefs. The Math Works offers a C library with functions for accessing Matlab files. You can use this library to create a DLL. Then import the DLL into LabVIEW by using Call Library Function VI located under Functions>>Advanced palette.
To call Matlab scripts from within LabVIEW, you have to have Matlab installed on the machine. The Script Node (Matlab script) function is located in Functions>>Mathematics>>Formula palette.
Here are some useful links:
- description of those C functions
[http://www.mathworks.com/access/ helpdesk/help/techdoc/apiref/apiref. shtml]
- how to download and compile (it will be a little bit different if you want to use CIN)
[htt
p://www.mathworks.com/support/ solutions/data/8757.shtml]
- MAT-file format if you want to develop your own LabVIEW utility to do the job
[http://www.mathworks.com/access/ helpdesk/help/pdf_doc/matlab/ matfile_format.pdf]
Hope these suggestions pointed you in the right direction.
Zvezdana S.
National Instruments -
Save new mat file: MATLAB
Hello,
I am not able to save a new MATLAB file (ie. create a file) from LabVIEW . This is possible in MATLAB by using the command: save(filename, 'variable'). When I do this in LabVIEW for a new file, I get a message saying that the file does not exist. This does not happen in MATLAB. How do I get around this? In my program I need to create many mat files with data collected while LABVEIW is running.
I would appreciate any incite in this matter,
Thanks,
IvankaHere is a sub vi. Please let me know if you need more clarification. Thanks,Ivanka
Attachments:
case 12 write LANDMARKS.vi 27 KB
Maybe you are looking for
-
Error installing cube 0CDM_C2 from BI content
Hi Guru's, I am trying to install the cube liability 0CDM_C2 from the BI content. we are on BI 7.0 I am getting a error IC=0DBDUNS_NUM IS=0DBDUNS_APPENDIX_ATTR_1 error when checking the update rules Message no. RSAU461 can anybody please help me on t
-
Miracast in a Company / Deploy over GPO or Powershell
HI Has anyone a Idea how we can deploy on all Tables the Miracast Adapters from our Company. wand deploy all Miracast Beamer from the hole Company<o:p></o:p> I am looking for Powershell or GPO.<o:p></o:p> But nothing is full working.<o:p></o:p> <o:p>
-
How do I makr comcast my home page?
When I sign into FireFox, I have tried making Comcast my home page. It always reverts back to google.
-
Hi Friends, I have been trying for finding menu path for transaction "FBZ4",But i coudnot find out even i tried in each and every corner of Menu in SAP & other forums and check with friends.I couldnot find.Finally i come to you.Please provide the Men
-
Pix 501 Port Redirection with outside Dyn IP for DVR
Hi, I have a pix 501 6.3 version soft. I need to access my cameras from the net. the camera address is 192.168.1.60:1042 my ISP outside is dynamic. The following is my config, please let me know what is wrong with it. PIX Version 6.3(5) interface et