Labview - Array of fixed size to receive serial data? - arrays

I am receiving 128 byte data continuously every second from serial,
I just want to know how can I replace this data to the starting index for each iteration in my byte array?
how can I do it?
-Thanks
I created an byte array and feed my serial string output to it via string to byte array converter

You could implement circular buffer in this way:

If I understand correctly you want to see the current iteration in the Array Indicator
If so, just place the Array Indicator inside the loop
Note that the Array indicator and the wire connected to it is not the same data type, there is a convert, you can see that it's different colors (orange and blue) and there is red dot where it's connected.
But if you want to collect all the data you received you should right click on your loop output and select Indexing
You would also need to change your indicator, just delete the current one and than right click on the wire -> create -> Indicator.
Or Hirshfeld
Control SW Engineer

Related

How to reverse an array in groups in C

I'm trying to do and make a software driver for one old device and i added bitmap support to it successfully. The problem is that all bitmaps are vertically flipped and I need somehow to flip them around.
My array has 230400 elements(for the resolution 320x240 as 320*3 colors is 960 elements per one y pixel, so 230400 in total)
I tried this one from Reversing arrays in C yesterday but today i realised that i need to switch every 960 elements from start to end to (i think) have it vertically flipped.
I also tried one array reverse guide on the internet but it reversed all elements and so colors changed and it flipped horizontally after sucessfully flipping vertically
For importing the 320x240 bitmap i used https://stackoverflow.com/a/9296467
,renamed data do BMPdata and added my piece of code to the B,G,R to R,G,B code
data[(i+y*320)] = BMPdata[i];
data[(i+y*320)+1] = BMPdata[i+1];
data[(i+y*320)+2] = BMPdata[i+2];
This piece of code sets every pixel in red(first line), green(second), blue(third) to the needed value from BMPdata array.
So i expect it to flip vertically because the one used before was not working and the second one which reverses the whole array from 0-230400 to 230400-0 changed also colors(which is logical for me) but also flipped the image horizontally so i also can't use that.
I want it to have every 960 elements switch from start to end without changing anything in them, so in example:
i have array of 5760 elements
960-1920: Test of the second line.
1920-2880: Third test
2880-3840: 4th line of text
3840-4800: Nearly the last thing.
4800-5760: Last line.
I expect it to flip like this:
0-960: Last line.
960-1920: Nearly the last thing.
1920-2880: 4th line of text
2880-3840: Third test
3840-4800: Test of the second line.
4800-5760: This is a test of the first line.
But it looks like it flipped like this with the reverse array thing:
0-960: .enil tsaL
960-1920: .gniht tsal eht ylraeN
1920-2880: txet fo enil ht4
2880-3840: tset drihT
3840-4800: .enil dnoces eht fo tseT
4800-5760: .enil tsrif eht fo tset a si sihT
There are several options. Just two of them are for example:
Instead of a 1-D byte array use a 2-D byte array with Y in the "outer" dimension and (X * colours) in the "inner" dimension. Use memcpy() to copy a whole pixel row without changing the sequence of bytes in it.
Define structs for pixel and row and define the bitmap as 1-D array of rows. You can copy a struct value (one row) by a simple assignment which will be compiled into a memcpy() behind the scene.
The beginner's way could also be to use two nested loops, one for Y and one for (X * colours). The Y loop will flip the bitmap while the X loop will keep the sequence.
I would go for the struct as it is more readable and implements what you mean. And you don't want to work on bytes, you want to work on pixels and rows.

LabVIEW: Array didnt store data

i want to store data like that, i am new in labview so its create confusion for me, if someone please correct this and explain it in details. It works but it does not display store data in front panel.
I highly recommend that you take a moment to read about Shift Registers. All you need is to create two shift registers, each on one side of the loop (one for the input and the other for the output). After you will need to wire the incoming value from the shift register to your array, and wire the outbouding value to the output register, as shown in this image from the tutorial.
Arrays will not store the data,instead you can use shift registers to store data into arrays.

How to add next and previous buttons in matlab?

We create a matlab gui for registration.In that form we have to see each images from an array on the buttons clicks. we need to be implement two pushbuttons ie 'next' and 'previous'. when we click previous we have to see previous image on the axis and vice versa. plz help us. Thank you in advance.
Well, the steps are pretty straightforward:
In your GUI's OpeningFcn you should add code to load the images from the folder:
create a cell array filed in handles, e.g. handles.img_store;
load images one by one in handles.img_store{:} using imread();
create a current image index, e.g. handles.img_index, and initialize it to 1;
display the current image using display_current_image() function—see 4.;
Write the callback for the pushbutton "Next" to increment handles.img_index, reset it to previous value if it goes out of bounds of handles.img_store, then call display_current_image()—see 4.;
Write the callback for the pushbutton "Previous" to decrement handles.img_index, reset it to previous value if it goes out of bounds of handles.img_store, then call display_current_image() function—see 4.;
Create a function, e.g. display_current_image() that will take handles as argument and, using the image() function, displays the image with the index handles.img_index in the cell array handles.img_store
I will not write code, not until you try to write some code first. :-)

creating a character array with gff file

Could someone please help me with creating a "character array" with this sort of data:
ftp://ftp.ncbi.nih.gov/genomes/Bacteria/Escherichia_coli_ATCC_8739_uid58783/NC_010468.gff
Instruction from our collaborator:
One can copy and paste a gff file into a character array by typing gff={} and then copy and “paste excel data”
But I can somehow only save it as a cell array and hence the script downstream can't run properly.
additional info
I need to use the .gff file in a .m script (that I got from someone else) to parse my sequences.
Here's the part of my script that I think pertains to my question:
genelist=gff(:,3);
starts=gff(:,4);
ends=gff(:,5);
names=gff(:,9);
genelogical=strncmp('gene',genelist,4);
Therefore I want 9 columns with information like this:
1. seqID;
2. source;
3. type;
4&5. start and end;
6. score;
7. strand;
8. phase
9. attributes
Also when I saved the cell array as "cell", and tried to convert it into a character array by typing
char(cell)
I got this error message:
cell elements must be character arrays
So guess that doesn't work...
edit over
Anyone has any idea?
Thanks,
Joyce
The instructions you were given are referring to the following context menu item accessible from the "Variables" editor:
First, run at the command line gff={}; to make an empty cell array. Then double click the gff variable in the Workspace tab to get the above editor window. Click on the square regino to the top left of the table to select all cells, then right click to get the displayed menu, and paste the data. You should end up with the following if the paste worked correctly (it could actually take a couple of minutes - check CPU usage):
Then the commands you posted work. The strncmp says definitively that as cell array is needed.

Quick Array Population

I have a application that will capture the screen and I want to write the captured information to an array, this takes AGES as the array ends up being +2million values. I am iterating and adding the values to the array, is there any way quicker (eg binary operations)? Should it be this slow? Why is it?
Assuming your GetPixel'ing the screen pixel by pixel, its the GetPixel call that's slow (it interrogates the display driver) not the (pre-dimensioned) array assignment.
You can instead use the getdibits() api which will copy the DC's colour info into a buffer in a single call.
Here is a C++ example, but the methodology & call sequence is the same as for VB.
Figured out why it was so slow, it was because I was using ReDim on every iteration of the loop - thanks for the help anyways
Martin

Resources