LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

mathscript csvread error

I've been wrestling with this one:

 

Mathscript vi with some csvread() statements (copied in from an old Matlab program I'm converting).

 

I run the vi and it generates a file not found error:

 

Error -90001 occurred at Error in function csvread at line 1.  LabVIEW:  File not found. The file might have been moved or deleted, or the file path might be incorrectly formatted for the operating system. For example, use \ as path separators on Windows, : on Mac OS, and / on Linux. Verify that the path is correct using the command prompt or file explorer.
=========================
NI-488:  Nonexistent GPIB interface.

Of course before this I made sure to set the path using the Mathscript window options menu to the full path where the files are (and the files are there).

 

Here's the rub: if I open up the Mathscript window and cut and paste the exact code from my vi into the command line - it works perfectly - no errors.

 

I must be doing something wrong. Is there maybe a global LV project search path that needs to be set or something. BTW: it's weird that the error comes from NI-488 GPIB interface - I'm not connected to any hardware - it's a completely sw application right now.

 

Thanks in advance for any suggestions,

 

Tom 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 1 of 11
(4,453 Views)

Hi Tom,

 

"BTW":

The error number is used twice and so you got two possible error reasons. Pick the one that applies, i.e. the first one Smiley Wink

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 11
(4,447 Views)

Is the path defined as a relative path (such as \subfolder\my file.csv)  or as an absolute path (such as c:\LabVIEW\My Data\subfolder\my file.csv)?  My guess is that it is a relative path and you have a different starting path in one context versus the other.

 

As for the GPIB message, some error codes are shared between LabVIEW and GPIB.  Because you are not using GPIB, that part of the error message can be ignored and just pay attention to the LabVIEW version of the error code of file not found.

Message 3 of 11
(4,442 Views)

Thanks for the quick replies.

 

Just checked, the path is absolute (c:\documents and settings\me\my documents\my working directory).

 

Any other suggestions - Thanks,

 

Tom

0 Kudos
Message 4 of 11
(4,433 Views)

I figured it out:

 

The offending line of code was:

 

tpl_p1r = csvread('tpl_p1r.csv','B2..C2');

 

I changed it to:

 

tpl_p1r = csvread('tpl_p1r.csv');

and then indexed the values I wanted in the array explicitly on another line: x = tpl_p1r(2,2);

 

Funny though - the original line works fine as I said before in the Mathscript window.

 

Oh well I found a bug but I got it working.

 

Thanks,

Tom 

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 5 of 11
(4,424 Views)

Strange.

 

I tried your line in LV 8.6.1 along with an example file I had created in the Mathscript node based on the csvread example in help and had no errors.

 

I'm glad you found a way around it.

0 Kudos
Message 6 of 11
(4,418 Views)

Hello every one,

I got the same problem. I can not use csvread () comand with with Mathscrit.vi but it works on Mathscript window.

 

I run the vi and it generates a file not found error:

 

Error -90001 occurred at Error in function csvread at line 1.  LabVIEW:  File not found. The file might have been moved or deleted, or the file path might be incorrectly formatted for the operating system. For example, use \ as path separators on Windows, : on Mac OS, and / on Linux. Verify that the path is correct using the command prompt or file explorer.
=========================

NI-488:  Nonexistent GPIB interface. 

 

This is the simple script which I used;

 

data=csvread('a.csv');

t=data(:,1);

y=data(:,2);

plot(t,y);

 

 

 

0 Kudos
Message 7 of 11
(4,337 Views)

Howdy Postdoc,

 

I assume you've checked into the path issue as well as parsing out the data suggested by the other two solutions to this thread.  One additional suggestion I have is to import the .csv file outside of the mathscript window using the Functions Palette » File I/O » Read from Spreadsheet function.  That way you can get all of your data into LabVIEW and feed the array directly into the Mathscript node.  Please let me know if for some reason this will not work for you.  Have a great day!

Sincerely,

Chris G in AE
0 Kudos
Message 8 of 11
(4,312 Views)

Dear Chris,

Thank you very much for your kind advice. I will try it and let you know.

Thanks again,

Have a great day,

 Yours truly,

Ranjith Amarasinghe 

0 Kudos
Message 9 of 11
(4,304 Views)

Dear Chris,

First thanks for your advice.

 

BTW, I could solve it just adding absolute path.

 

The offending line of code was:

 

data=csvread('a.csv');

t=data(:,1);

y=data(:,2);

plot(t,y); 

 

I changed it to:

 

 data=csvread('F:\1MY-DATA\Labview\Mat\a.csv');

 t=data(:,1);

y=data(:,2);

plot(t,y); 

 

it worked,

 

Thank you very much, Chris

 

Have a great day! 

 

 

0 Kudos
Message 10 of 11
(4,287 Views)