VBA modifying inside array - arrays

I am sure this is a very simple question but what's the best way to multiply everything in an array with say 100, or take square root of everything inside an array, without copying it or a for loop?
Thanks!

There is no way to do that in VBA.

Related

How creating an array with array elements using Visual Basic

I want to work with a dynamic array using visual basic and I want that each element of the array will be an individual dynamic array too. How I should proceed? Thanks.
Read this - https://msdn.microsoft.com/en-us/library/aa716275(v=vs.60).aspx
And also this, in case you decide that reDim-ing things is annoying: https://msdn.microsoft.com/en-us/library/system.collections.arraylist(v=vs.110).aspx
Essentially though, you want to make an array and fill it with arrays. Then just treat those arrays independently for re-sizing purposes.

Using jsonencode with length 1 array

When using the MATLAB jsonencode function it seems very difficult to convert size 1 arrays into the correct JSON format i.e. [value]. For example if I do:
jsonencode(struct('words', [string('hello'), string('bye')]))
Then this produces:
{"words":["hello","bye"]}
which is correct. If however I do:
jsonencode(struct('words', [string('hello')]))
Then it produces:
{"words":"hello"}
losing the square brackets, which it needs because it is in general an array. The same happens when using a cell rather than an array, although using a cell does work if it's not inside a struct.
Any idea how I can work around this issue?
It seems this can be solved by using a cell rather than an array and then not creating the struct inline. Like
s.words = {'hello'};
jsonencode(s)
Output:
{"words":["hello"]}
I presume when created inline the cell functionality of matlab is actually trying to make multiple structs rather than multiple strings. Note that this still won't work with arrays as matlab treats a size one array as a scalar.

Indexing ones into a matrix of zeros without loops

I'm fairly new to MATLAB and I need some help with this problem.
the problem is to write a function that creates an (n-n) square matrix of zeros with ones on the reverse diagonal
I tried this code:
function s=reverse_diag(n)
s=zeros(n);
i=1;j=n;
while i<=n && j>=1
s(i,j)=1;
i=i+1;
j=j-1;
end
but I want another way for solving it without using loops or diag and eye commands.
Thanks in advance
The easiest and most obvious way to achieve this without loops would be to use
s=fliplr(eye(n))
since you stated that you don't want to use eye (for whatever reason), you could also work with sub2ind-command. It would look like this:
s=zeros(n);
s(sub2ind(size(s),1:size(s,1),size(s,2):-1:1))=1

Swift Similar Element Array

If I have an array with elements linked to xassets with names like "card1", "card2", etc up to "card100" is there a quicker way to write these elements in the array format without having to write out all 100?
Also if this has been answered already please let me know or link to it. About 2 days into trying to teach myself to program.
Not exactly sure what you're asking but you may want to look at loops - Swift Loops. You can add items to an array in a for loop from 1 to 100.
Is this what you are looking for ?
let cards = Array(1...100).map({"card\($0)"})

Add element to next unused index - C

I'm sure others have already asked this, but is it possible to insert an element into the next available index of an array without using a for-loop to find that index first? Almost like a list.add() function but for arrays in C.
no, you will have to loop through the array.
If it's really list functionality you want you could implement a simple linked list instead of using arrays, for example like this: http://www.cprogramming.com/tutorial/c/lesson15.html

Resources