LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

saving data as a matlab file and handling of clusters?

I am currently trying to write up a tool to allow me to save my files as a matlab file, as we still use matlab for the majority of our data processing. From searching this site I found the program conv2mat.vi which works when I use it on a case by case basis. Now I would like to make it a more generic subvi that I can embed in a program.

 

I want to feed it a cluster of numbers, 1D and 2D arrays. I want to strip the name from the cluster, and also gain insight as to whether or not I have a 1D, 2D or single number value. If it is a single number value I would want to convert that to a 1D array of one number. Then I would like to via a for loop write it all into a matlab file which I can open up in matlab on another computer. So far I have had no problem using the conv2mat.vi file and even using it to store multiple variables. The key is that I need to know up front if I have a 1D, 2D or single number array. So how do I get this program to work with a cluster?

 

The big thing I am missing right now is how to figure out what type of data my cluster contains. I think if I can do that I will be all set.

 

Any ideas?

 

 

Download All
0 Kudos
Message 1 of 6
(2,926 Views)

One more thing to help here, I have been searching around, I found the tool called "Cluster Info" you can see a screenshot of it in my code as well as the front panel. It outputs more or less exactally what I need. Namely if you look at the photo it tells you if you have a numeric, double, 1D or 2D array. so now the question is for each element in the cluster how do I programmatically determine if I have a 1-D, 2-D or numeric? Then I think from there I would use the variant to data tool to put it back into an array and save the variable as a matlab file.

 

Any ideas? One other minor issue in my convert to matlab code I can't seem to figure out is when I save the file on my end I have 6 decimal precision. However when I bring it up in matlab I only have 4 decimal precision. Any ideas on what I need to modify to control that so I get 6 in both?

 

Thanks,

 

Adam

Download All
0 Kudos
Message 2 of 6
(2,923 Views)

I am surprised at this point in time no one has chimed in, seeing how many people have tried this in the pasta. I actually solved the whole clusters issue, but now I have discovered another problem that is making me throw in the towell on this one as I just can't explain it.

 

I am finding for some silly reason while the code will work in one VI it won't seem to work in another. See my photos below. The one where the code works, I have created the whole thing as a subroutine inside of a greater VI which I can not publish due to proprietary code. Next I tried pulling out the functioning part of the code and putting that in a stand alone file. See the photo where the code doesn't work. I have also ran the same code that doesn't work with both 1 and 2 variables. Each time Matlab can't open it. I am using the same to MAT subvi in each of these. For some reason though when I run the code in the working picture it runs, and I get a nice little mat file that I can open in Matlab. When I run the same exact code as a standalone I get the matlab error code every time.

 

I have tried reviewing every possible variable I can think of and worked with them. In all cases the two new VI's I made the code doesn't want to give me a valid mat file. However in the greater program it does! I am really stumped at this point. So unless I can find a better convert to matlab file code I don't think this will work.

 

0 Kudos
Message 3 of 6
(2,915 Views)

Hi Adam,

 

I have a couple of questions/suggestions for you, as well as some observations. First, I see that you're calling your subVI twice when running the code that works, but only once when it doesn't. I know you mentioned that you also tried it with 2 variables, but if you copy the data on the array going into the two instances of the subVI where the code works into your new standalone VI, does that data successfully create a working mat file? More clearly stated: if you use the exact same values in your standalone that you use in the working file, do you get the same error?

 

Next, I see that you have a space in one of the inputs of your subVI (i.e., "Array 1"). What happens if you change that space to an underscore or just completely remove the space?

0 Kudos
Message 4 of 6
(2,893 Views)

Hi Drew,

 

Thanks for getting back to me, I went and took your advice, it turns out the empty space looks to be causing all the issues. With that being said, I should be able to start moving forward again now.

 

Thanks,

 

Adam

0 Kudos
Message 5 of 6
(2,884 Views)

Now that I know it was my space or lack of underscore that was causing the issues I was able to fix that problem and it works well. Now the next question I have, see my attached code, Convert2Matfile.vi. You will also need my conv2mat.vi too. How do I input a generic cluster into a subVI? By this what I mean is if you look at my current code you will see I have a 1D a 2D and a Numeric array in there. What I want to be able to do is just wire over any old cluster to the subVI and have it suck out the data from whatever the cluster is. I hope I am making sense right now, but what I want to do is in one VI feed this subVI a cluster with say 10 1D arrays, then in the next have 20 1D arrays, 10 2D arrayys, and a few numeric values and so on.

 

How do I do this, right now my code will only take what my cluster contains and each of those cases above I would need to set up individiually. Which really negates the value of what I am trying to do with this code.

 

Thanks,

 

Adam

Download All
0 Kudos
Message 6 of 6
(2,880 Views)