Loading Matlab matrix into Labview array - arrays

I have a matrix which contains GPS waypoints (4 columns - lat,long,h,time) and I would like to use this in a Labview programme to control a UAV.
The code I am working from has a waypoint array to input the waypoints manually from the front panel, but I would like to load this set of points.
I have never used Labview before, so I am having trouble modifying the programme.
Thanks!

Elaborating on a comment, one way that you could do this is to save your MATLAB matrix in a format that you can easily read in LabVIEW, for instance CSV. In MATLAB, save your matrix to a CSV file:
csvwrite(filename, mymat)
where filename is whatever you want it to be surrounded by quotes, e.g. 'GPS_data.csv', and mymat is your data. Then in LabVIEW you can read the contents of the file into a 2D array using Read From Spreadsheet File.vi. Each row of the resulting 2D matrix will a single waypoint, and you can process that data however you see fit. An example that does nothing but display each row after a short delay is shown below.
You could hard-code the filename that you want to read into the Read From Spreadsheet File.vi, or execute your VI without anything wired in to be prompted for a CSV file to read.

Related

Issue with writeVideo/ VideoWriter MATLAB

I'm a beginner so sorry in advance for the mistakes.
I have a set of data from a camera recording saved in a 4D array with these dimensions (250x300x10603x12).
The first is the dimensions of the video (pixels). The 10603 are the FrameRatexTime. 12 are the subjects I recorded.
I extract one subject at a time for analysis in this way:
subj1 = data(:,:,:,1);
This brings me to an array containing the frames of subject 1, which I can display with implay.
Now I would like to write a video of this new array and save it in .avi format, I use this code:
v = VideoWriter('subj1.avi')
open(v)
writeVideo(v,subj1)
close(v)
but it keeps giving me this error
Error using VideoWriter/writeVideo (line 410) IMG must be an array of
either grayscale or RGB images.
In fact, looking at the shape of the array, there is nothing that points to a grayscale or RGB index. How can I get a .avi file in this case? Do I have to transform the array?
Why does it still display the video with implay?
clarification: the fact that I have to transform the array into an .avi file is because I will have to analyse it by exporting it to Python with OpenCv.
In fact, if I export the .mat file directly to Python, I can't get the list of Frames.
Matlab's documentation for writeVideo says that for a sequence of grayscale images like you have, it is expecting a "height-by-width-by-1-by-frames" array. You are only passing it "height-by-width-by-frames".
So, you need to reshape your subj1. Maybe try doing it like this:
newsubj = zeros(250, 300, 1, 10603)
newsubj(:,:,1,:) = subj1
and then save newsubj instead of subj1:
writeVideo(v,newsubj)
Finally, I think you may get some lossy compression when you save as an avi, so it may not be the best way to export it from Matlab and importing it to Python.

Trying to populate an array from a text file

I'm using xcode, swift 5.0.
I have a multidimensional array for a tableViewController to give a list with different sections.
I would like for the array to be taken from a text file which is stored remotely (so that the array contents can be updated without an app update).
Any advice on how to code for this?

Issue reading .txt file in Matlab. I want to get an array from this file without the unnecessary info it contains

I'm having trouble reading a .txt file to get some data. I want to be able to change some of the values this data contains.
At first, I used this:
A=importdata('myfile.txt');
And got this cell array:
Now what I want is this:
1) Get rid of the headers (the information from cell 1 to 22). That could be easily done by simple indexing (creating a sub-array using just the info from cell 23 to the end of the file).
2) I want to separate the information into different cells, using these identifiers. But I don't know how to separate them into different cells of the array.
'# item bepoch ecode label onset diff dura b_flags a_flags enable bin'
3) Do the same in step 2 to fill those columns with the data in the rest of the cells.
I'm trying to use this approach, but I'm not getting the expected results.
If someone can help me, I'd be glad.
Have you tried dragging the file into the variable workspace window and using the data import wizard? It has some nice features that normally take care of what you are trying to do automatically. Unfortunately, it seems that your text file may have unconventional spacing, but Matlab may be able to handle it if you set the delimeter to ' ' or suchlike.

display mat file in matlab

I want to display mat file's content to see all the results. I know that I can load it and then double click on it the content are display in the workspace, this case happen when the mat file content few information but when I have mat file content information for more than 13000 record I can't display it. could please any one help me to find any way to display mat file as table?
thanks
I do not know the format of your data (multi-dimensional, structs, cell-arrays), but there is a function called "openvar" which can be very useful for these things.
Let's define a large random 500x500x10 3d-matrix:
large = rand(500,500,10);
This variable contains 2.5 million double-values and takes up close to 20MB of memory. Opening this in the variable editor by double click in the Workspace window on "large" will usually (atleast on my system) give the following message:
"Cannot display summaries of variables with more than 524288 elements."
But you can use the "openvar"-function to open certain parts:
openvar('large(:,:,1)'); %# pass the argument as a string.
This will open the first "layer" of matrices in your Variable Editor (a 500x500 matrix in this case). This is useful if you need to look into certain parts of a large variable.
Of course you can always define new variables that contain subsets of your larger variable:
less_large = large(:,:,1);
... and then open "less_large" in the variable editor by double clicking on it in the workspace-window. But sometimes the "openvar"-method is a bit faster/easier.
You have a few options. Starting from a clear workspace, you could load the mat file into the workspace. Anything now in the workspace is in the mat file. You can use the variable viewer or parse with scripts.
If you have the Simulink toolbox, you can use Simulink.saveVars to save the contents of the workspace to a human readable m-script that would generate the same contents. It's a shame that you need Simulink to do this, as this function has nothing to do with Simulink.
How about after loading the data, and use whos to display the variables in current workspace? Note that you may want to clear all the other variables before displaying them.

Easy way to plot and display arrays?

First post here. Using C in Visual Studio 2008. Can work with VS 2005 if necessary.
How do I display numerical data in arrays as in a spreadsheet?
How do I plot numerical data in arrays?
These seem to be simple questions. But I cannot find solutions. So far, I would print the data to a file, import into Excel and view/plot. However, with this code there are too many arrays--so the print/import/plot is tiring.
Some constraints.
I do not want to write 20+ lines of code to do the above. MATFOR or Array Visualizer let you do the plotting with a one line function call.
They cannot display the data in a convenient format. I would like to display the data and the plot in one or two windows so that they are visible simultaneously.
This is a win32 console application---all the code is portable.
Will be using these during debugging.
Free or paid.
While I am looking for something specific, the requirements are substantially the same for any one doing numerical work with arrays and matrices--displaying data and plot simultaneously.
I am hoping that a such a tool has been written and is available.
I am also open to a solution that outputs the array data to an Excel sheet (can keep Excel open) and if it can also plot that can be great but I can live without plotting.
PS: I need this only when debugging the code.
I use ArrayDebugView which is a plug-in you install in Visual studio and draws graphs out of arrays while you are debugging your application. It works as a visual way of variable watch in debug mode. You don't need to write a line of code.
I can't think of any library that would enable what you want in a console app in less than 20 lines of code. My suggestion would be instead to script the plotting-step using MATLAB og GNU Octave to do the actual plotting.
In order to display numerical data in array, you should add the pointer to the first data element you want to observe, into the watch --- if you want to observe the array from the beginning, it would just be the array name, which is the pointer to the first element. In order to view more then one element, you add a "," after the pointer, followed by the number of element you want to observe.
For example, in order to observe the elements of float farray[100];, you should add to the watch farray,100.
In order to plot, you can copy-paste from the watch to your plotting software (i.e. excel), but it is not very convenient as you cannot copy the data column alone, but the columns to the left and right as well, so it involves extra manual editing.
I use GNUPlot (http://www.gnuplot.info/) to display my performance/speedup measurements.
I print my numbers to stdout and wrote a bash script that combines these numbers and calls gnuplot for rendering.
I made a simple plotting program for that purpose. There is only a textbox where I paste the data and a chart where it's drawn.
The data needs to be in either form:
with an automatic X (increment by 1 for each value): seriesName value
for both X and Y specified: seriesName xvalue yvalue
Most of the time I used to plot data from tracepoints.
I copy/paste the whole output window of VS, the plotting program ignores anything that doesn't follow these 2 forms (so I don't have to cleanup the string and put it in excel and all).
It does line, point, colum, area charts and save image, copy to clipboard.
MiniPlot
There are several ways to do this but this will require writing some code. Visualizing data is generally easy and straight forward but visualizing data exactly the way you want them to look will require some additional code and work.
There are several options to visualize data:
A combination of BASH and GNUPLOT
Use MATLAB or OCTAVE for all your calculations and visualization
Use PYTHON and SciPy and matlibplot libraries.
Gnuplot is a great tool to plot data but it is cumbersome to use. It looks fabulous if you invest time to get the plots right and combines excellent with LaTeX and has a good fit implementation for arbitrary functions. Visit http://gnuplot-tricks.blogspot.ch/ great site to learn all about gnuplot.
Numerical programs such as MATLAB and it's open source equivalent OCTAVE are great because they are fast implementation languages for numerical programs and have extensive additional libraries especially MATLAB. For high load numerical computing it is really slow and the plot library is only good for basic plotting needs.
Using PYTHON and its scientific programing libraries (SciPy and matlibplot) are a great combination. This allows excellent plot which are not as cryptic as gnuplot to plrogram and it is more flexible than MATLAB in plotting. Additionally it gives you a environment for numerical programing like MATLAB.

Resources