How do I replace an array element in LabView? (2d array of pictures) - arrays

so I have a final project for a class where I need to make a video game in LabView. The issue I'm having at the moment is that I can't figure out the 'right' way to put 'yourShip.png' into the 2d array of 2d pictures at [0,0]. Every tutorial I can find basically has exactly what I have down below in the screenshot, and it makes sense to me. However, running the program quickly shows that it does nothing.
To describe the code, I have a path constant that leads to the picture, which feeds to a draw flattened pixelmap function. Up to this point I know the code works, since creating a test indicator reveals as such. However, next I try to use the replace array subset function to replace the (default blank) 2d picture at [0,0] with yourShip.png. 'screen' is a 5x5 2d array of 2d pictures. The local variable of the same name being outputted to is indeed the very same array.
My main guess with why my code doesn't work is because of the way I'm taking screen as the input variable and then outputting to it via a local variable. However, if this is wrong, I'm confused with how I should do it. All I want to do is 'spawn' the image at the correct index.

The replace array subset works quite literally, i.e. it can only replace existing elements.
If there is no element at the specified index because the array is smaller, the function will do just nothing.
I guess your array is empty, so, initialize your screen array first to a size of at least 1x1.

Related

replace page of array with another using paste() R

I have a 3d array with lots of pages (or whatever you call 3rd dimension). I am trying to stick that array into a loop, and loop through the pages to fill in values.
In my real dataset, I'm manipulating values with a handful of custom functions, so the way it works best to minimize the amount of retyping I would need to do when changing variables is to create a new array inside the loop, make changes to that new array, then replace the new page in its spot in the original array. However, I'm having a hard time plugging the new page back into the original array. Example follows.
code="A" # I'll be running this loop with various name codes
assign(paste0("testarray",code),array(dim=c(5,5,20)))
# creates array "testarrayA" . I'm using assign(paste()) because I will
# do this with many different array codes, and I want to only change
# the code value each time for ease
set.seed(5)
testarrayA[,,1] <- runif(25,3,20) #fill first page
Then I want to run this array through a loop to change the values on each page. In the real code, the changes are made with somewhat complex custom functions, so again, for ease, I start by making a smaller array, changing that, then trying to plug back into the array from above. See following.
# this loop doesn't work at the moment, so just run lines
# inside the loop individually to attempt. set "page" object as 1
for(page in 1:dim(get(paste0("testarray",code)))[3] ){
# for pages 1-end of third dimension (20)
temparray <- get(paste0("testarray",code))[,,page:(page+1)]
# create smaller array of only current and (blank) next page of original array
temparray[,,2] <- temparray[,,1]*2
# do functions to change the values on the next page of temporary array.
# (just multiplying values by 2 for this example)
# try to plug in temporary array[2] as original array[page+1].
# both of these codes give me errors at the moment, but these are
# the options I have tried so far.
# trial 1:
get(paste0("testarray",code))[,,page+1] <- temparray[,,2]
# trial 2:
assign(paste0("testarray",code)[,,page+1],temparray[,,2])
}
I believe the problem comes from not being able to use paste() in the receiving end of an assign command. The first trial listed above returns error "target of assignment expands to non-language object," which I'm not quite sure how to interpret, and the second, "incorrect number of dimensions," which shouldn't be the case. When I highlight and run each object individually, they have the same dimensions, so I don't know what I'm doing wrong.
Basically, I need to know how to use paste() on the receiving end of an assign function such as <- or assign(), or if there's a reasonable workaround for the errors I'm getting. I know I could just omit the creation of the smaller temporary array, but in my actual code, that would make a lot more work by requiring me to change names a bunch of times in each command inside the loop when I run on a new dataset. I'd rather just change the "code" if possible. Thanks!

Array (class) filled with non nil values stays empty

I am currently having trouble filling up an array of customClass.
I try to fill it with a jsonFile. During my json parsing (using swiftyJSON) i loop and fill my array.
The problem is, at the end of my loop, it is still empty. I tested it in different ways, and here is my code:
That's the file where the problem is. In my loop I fill an Annotation, that I add with append to my array. The problem is what my print return. Here is a part of it:
It's just a small part of a huge jsonfile. And, my tmpAnnot.name is correctly printed every iteration. But when it comes to my Array, nothing.
So I'm completly lost and hope you could help me ^^
(And for the information, here is my custom class) :
And btw, I tried to print my array.count, and it's nil too
Im so sorry if the question has been posted. I couldn't find it in the entire website.
Change your JSONAnnotationList declaration to be an non-optional and assign it an empty array
var JSONAnnotationList: [UGOAnnotation] = []
You see, you have never created an array so there was nothing to be printed.
The whole point of optionals is to use them sparingly, not everywhere.

How can I store images in an array in octave?

I have an read image got with the imread function.
Now, I need to create a random number of images with noise, appling the noise function.
The main problem is: The amount of images will be random. so I tried to create a cell array and store the images in each position (array(1)=img1, array(2)=img2, and so on). But using it, the array(1) and so on doesn't let me work with my image.
So how can I really put all of them in a array and use them normaly?
Tank you!
MATLAB and Octave have pretty much the same language.
Please try the following:
for i=1:length(images)
array_of_images{i}=images(i);
end
I think it should work something similar or exactly this

Copying part of array to a second array in C

I'm writing an image processing code to perform a median filter with a variable sized window.
The greyscale image has been read into an array image1, and I'm trying to copy a window selection of the array into a second array window. This is easy for a fixed sized window (3x3 window shown) as you can just say:
window[1]=image1[m-((win_size-1)/2)][n-((win_size-1)/2)];
window[2]=image1[m][n-((win_size-1)/2)];
window[3]=image1[m+((win_size-1)/2)][n-((win_size-1)/2)];
window[4]=image1[m-((win_size-1)/2)][n];
window[5]=image1[m][n];
window[6]=image1[m+((win_size-1)/2)][n];
window[7]=image1[m-((win_size-1)/2)][n+((win_size-1)/2)];
window[8]=image1[m][n+((win_size-1)/2)];
window[9]=image1[m+((win_size=1)/2)][n+((win_size-1)/2)];
In MATLAB you can generalise this to any sized window easily by using a vector in the array call:
window = image1(m-((win_size-1)/2):m+((win_size-1)/2),n-((win_size-1)/2):n+((win_size-1)/2));
I can't work out a way to do this in C, can anyone help me with this please?
Solved by using nested for loops with a pre-defined int outside the loop. Assigned to 0 at start of first loop then +1 on each iteration.
You will have to dynamically allocate memory for an image, whatever image may be, for an array then add it to your array. I don't know exactly how to do it in C, but in C++ it would look something like:
image = new Image [5];

Do arrays in AS2 have to be reset to the beginning when re-used?

I am working with an older and undocumented set of ActionScript (AS2) and I have found that an array, when looping through it the second time, does not give the proper results. It has been a while since I used ActionScript - does the array need to be reset before the second time through another for loop?
For instance PHP has reset() which returns the array's pointer back to the first item in the array.
There's is no such thing as pointers in ActionScript.
You can target each and every item in an Array by simply targeting it with myArray[index], and no pointer needs to be reset to be able to re-read it.
If your two loops produce different results, I would suggest looking into code that could change anything in it between the two loops or in the first one.
Maybe you could post it here ?

Resources