In vba I have a two-dimensional array that I need to split somehow into two separate arrays. I have looked at the split function but I don't see how that would solve my problem.
The array looks like:
shift(1)
shift(1,1)
shift(1,2)
shift(1,3)
and so on...
Now, what I need is to split this like so:
shift(1)
shift(1,1)
shift(2)
shift (2,1) -- was shift(1,2)
shift (2,2) -- was shift(1,3)
What's the best way to do this?
Thanks for helping me out here!
Related
I have two numbers [739 560] and I just want to know if it appears in a huge 2D array of size 9000x2
I cannot find a simple way of checking that.
Can anyone suggest anything simple? Thanks
You can do:
find(ismember(A, r, 'rows'))
a quite basic question. How do you replace a dimension of an array with a dataframe of the correct size (=matching the array in the other two dimensions)?
A simple working example: I make a small array of nrow=2, ncol=3, and 2 dimensions. I make a small dataframe which is also nrow=2 and ncol=3. If I try to replace one of the array's dimensions with the dataframe, it doesn't work properly and the array's dimensions are all messed up. What am I doing wrong?
arr<-array(1:12, dim=c(2,3,2))
df<-data.frame(13:14, 15:16, 17:18)
arr[,,2]<-df
dim(arr)
After reading this I wrote a naive attempt to produce this
col1
---------
1
4
7
from this
ARRAY[[1,2,3], [4,5,6], [7,8,9]]
This works
SELECT unnest((ARRAY[[1,2,3], [4,5,6], [7,8,9]])[1:3][1:1]);
But I in my case, I don't know the length of the outer array.
So is there a way to hack together the slice "string" to take into account this variability?
Here was my attempt. I know, it's a bit funny
_ids := _ids_2D[('1:' || array_length(_ids_2D, 1)::text)::int][1:1];
As you can see, I just want to create the effect of [1:n]. Obviously '1:3' ain't going to parse nicely into what the array slice needs.
I could obviously use something like the unnest_2d_1d Erwin mentions in the answer linked above, but hoping for something more elegant.
If you are trying to get the first element of all nested (2nd dimension) arrays inside an array (1st dimension) then you may use
array_upper(anyarray, 1)
to get all elements of a specific dimension
anyarray[1:array_upper(anyarray, 1)][<dimension num>:<dimension num>]
e.g, to get all elements of the first dimension
anyarray[1:array_upper(anyarray, 1)][1:1]
as in the code above. Please refer to PostgreSQL manual section on Arrays for more information.
I'v multiple arrays of [1x3], however I named them array1 array2 array3 and so on. What I want to create one array from all arrays such that array=array1(i,1:3) array=array2(i,4:6) and so on. How I can done this by looping or any suggestions regarding my approach, I actually want to access multiple arrays dynamic so that I'm going with this approach, any other suggestions are welcomed as I thought there will be slow computations and processing speed when my array size increases.
My Code:
for i=1:10
array(i)=array(:,i:i+3);
end
The easiest way is use cat function:
array = cat(2,array_1,array_2,array_3);
If you want to access array_i (i=1,2,3,...)
array_i = array((i-1)*3+1:i*3);
The jth index (j=1,2,3) of the array_i (i=1,2,3,4,...) can be accessed:
jth_index_of_array_i = array((i-1)*3+j)
The following doesn't work... Can you do 3d arrays in foxpro?
DIMENSION sqlresults[10]
select list_code, count(donor) as ndine FROM cGift group by list_code INTO ARRAY sqlresults[1]
edit:
ah, a google search for "vfp multi-dimensional arrays" turned up something ("vfp 3d arrays" didn't)
Foxpro only supports 2d arrays. Guess i'll have to fake it with some substitution (&).
The only problem with your code is that you included a dimension in the query. Try this instead:
select list_code, count(donor) as ndine
FROM cGift
group by list_code
INTO ARRAY sqlresults
That said, on the whole, you're better off putting query results into a cursor than an array.
Sqlresults[1] = sys(2015)
Select ... into cursor (sqlresults[1])
This way your array holds names of the cursors, and you can access their values like:
Select (sqlresults[1])
?fieldname
Or use eval or &