VB.Net create as many arrays as possible from one array - arrays

I have an Array lets say myarray ={1,2,3,4,5,6}
What I'm trying to do:
is generate as many as new arrays by changing each value with a value of the same array
example: myarray[0]=myarray[1] so first array will be {2,2,3,4,5,6}
then myarray[0]=myarray[2] so 2nd array will be {3,2,3,4,5,6}
later myarray[1] = myarray[0] so array will be {1,1,3,4,5,6}
and so on
I tried to think of many solutions but none of them work.

Related

How to assign a arrays values to a multi dimensional array in VBA

I have a multidimensional array that is setup to hold a "identity number" as the first part of the array, and then a set of values as the second part. Ie
Dim holder(8,2) as integer
I'm trying to make holder(1) equal to a already defined array, as it is to many different values to write
Instead of
Holer(1,1) = 1
Holder(1,2) =2
Etc
Do this
Holder(1) = Array(1,1,1)
Normally this wouldn't be a issue but I have multiple arrays
Ie
Holder(1) = Array(1,1,1)
Holder(2) = Array2(1,1,1)
How do I do this?
Another way to word it is put the values of array a into the holder array 1.

How to show elements of array?

I have a small problem. I created a large array.
It looks like this:
var Array = [
["text10", "text11", ["text01", "text02"]],
["text20", "text21", ["text11", "text12"]]
]
If we write this way: Array[0] that shows all the elements.
If we write this way: Array[0][0] that shows "text1".
If we write this way: Array[0][2] that shows
-2 elements
-- 0: "text01"
-- 1: "text02"
.
If we write this way: Array[0][2].count or Array[0][2][0] it will not work
How do I choose each item, I need these elements for the tableView
The problem basically is that your inner array is illegal. Swift arrays must consist of elements of a single type. You have two types of element, String and Array Of String. Swift tries to compensate but the result is that double indexing can’t work, not least because there is no way to know whether a particular element will have a String or an Array in it.
The solution is to rearchitect completely. If your array entries all consist of the same pattern String plus String plus Array of String, then the pattern tells you what to do; that should be a custom struct, not an array at all.
as #matt already answered but I want to add this thing
Why Array[0][2].count or Array[0][2][0] not work
If you Define array
var array = [
["text10", "text11", ["text01", "text02"]],
["text20", "text21", ["text11", "text12"]]
]
And when you type array you can see it's type is [[Any]] However it contains String as well as Array
So When you try to get Array[0][2] Swift does not know that your array at position 2 has another array which can have count
EDIT
What you are asking now is Array of dictionary I suggest you to go with model i.e create struct or class and use it instead of dictionary
Now If you want to create dictionary then
var arrOfDict = ["text10" : ["text01", "text02"] , "text11" : ["text11", "text12"]]
And you can access with key name let arrayatZero = arrOfDict["text10"] as? [String]

F# - assigning element in (jagged) 2d-array sets several elements [duplicate]

This question already has an answer here:
Array.create and jagged array
(1 answer)
Closed 6 years ago.
I'm experiencing some behavior in f# that i do not understand. I was trying to create a 2d table using nested arrays. The sub-arrays will have the same length, so I could have used Array2D. However later on I will need the table rows as normal arrays, so in order to avoid conversion from a multidimensional to a regular array I want to represent the table as a jagged array.
The following code is an example of how I initialize and assign elements in the table.
let table = Array.create 3 (Array.zeroCreate<int> 2);;
table.[0].[0] <- 1;;
I would expect this piece of code to set the first element in the first row. However, what it actually does is setting the first element in all three rows.
table;;
val it : int [] [] = [|[|1; 0|]; [|1; 0|]; [|1; 0|]|]
Why does table.[0].[0] set the first element in all three sub-arrays? I tried finding the memory addresses of the sub-arrays using System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement, and it seems to me that they are different, so they three rows are not the same array. What is going on here?
When you use array.create, it takes as an argument an object, not a function.
As a result, each element of the jagged array is a reference to the same array, so you get the observed behaviour.
Just use a function other than array.create to make the array

Arrays in matlab

I have a structure names eye_record which has 6 fields, one of which is x_pos_measured_deg:[1800x1 double]
I want to declare an array in such a way that using for loop, i can get all values of that specific field into a new array and do some work on them. Can anyone show me how to do that? here is m code:
arr=zeros(1,1800);
for t=1:length(eye_record);
arr(t)= eye_record(t).x_pos_measured_deg;
end
it gives me this error: In an assignment A(I) = B, the number of elements in B and I must be the same. How can i fix this? or how should i declare my array so that it won't give me this error? I want all the objects or values, which are in x_pos_measured_deg field to go into my new array.
Your eye_record is struct, not array, so you can not use indexing with eye_record. Your eye_record.x_pos_measured_deg is array and you have to loop through it. So the loop should be:
arr=zeros(1,1800);
for t=1:length(eye_record.x_pos_measured_deg)
arr(t)= eye_record.x_pos_measured_deg(t);
end
But actually, you can assign values directly like:
arr=zeros(1,1800);
arr = eye_record.x_pos_measured_deg';
since you declared arr to have size of 1x1800, and eye_record.x_pos_measured_deg has size of 1800x1.
Without arr=zeros(1,1800);, then no ' at the end:
arr = eye_record.x_pos_measured_deg;

Inserting data into an array sequentially

I am currently trying to figure out how to design some sort of loop to insert data into an array sequentially. I'm using Javascript in the Unity3D engine.
Basically, I want to store a bunch of coordinate locations in an array. Whenever the user clicks the screen, my script will grab the coordinate location. The problem is, I'm unsure about how to insert this into an array.
How would I check the array's index to make sure if array[0] is taken, then use array[1]? Maybe some sort of For loop or counter?
Thanks
To just add onto the end of an array, just use .push().
var myArray = [];
var coord1 = [12,59];
var coord2 = [87,23];
myArray.push(coord1);
myArray.push(coord2);
myArray, now contains two items (each which is an array of two coordinates).
Now, you wouldn't do it this way if you were just statically declaring everything as I've done here (you could just statically declare the whole array), but I just whipped up this sample to show you how push works to add an item onto the end of an array.
See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push for some reference doc on push.
In case you need to know the array's length when reading the array in the future, you can use the .length attribute.
var lengthOfArray = myArray.length;
Using the .push() method as suggested by jfriend00 is my recommendation too, but to answer your question about how to work out what the next index is you can use the array's length property. Because JavaScript arrays are zero-based The length property will return an integer one higher than the current highest index, so length will also be the index value to use if you want to add another item at the end:
anArray[anArray.length] = someValue; // add to end of array
To get the last element in the array you of course say anArray[anArray.length-1].
Note that for most purposes length will give the number of elements in the array, but I said "one higher than the current highest index" above because JavaScript arrays are quite happy for you to skip indexes:
var myArray = [];
myArray[0] = "something";
myArray[1] = "something else";
myArray[50] = "something else again";
alert(myArray.length); // gives '51'
// accessing any unused indexes will return undefined

Resources