NexusFi: Find Your Edge


Home Menu

 





saving values from a multi-dimensional array


Discussion in MultiCharts

Updated
    1. trending_up 2,212 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
infe2015
stockholm Sweden
 
Posts: 5 since Mar 2016
Thanks Given: 2
Thanks Received: 1

Hi i need too saving some values in a multi-dimensional array
i have done it i a singel array like this
Upp1 = CUpp[1];
Upp2 = CUpp[2];
Upp3 = CUpp[3];
Upp4 = CUpp[4];
Upp5 = CUpp[5];
CuppSum = Summationarray(CUpp,5);
but i cant find the solution for multi-dimensional.
Thanks Infe


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Saylors 41-Month HODL Breaks: Strategy Sells 32 BTC as $ …
Prediction Markets & Event Contracts
Trump Truth Social Fires Hormuz From 10% to 59% -- Arsen …
Prediction Markets & Event Contracts
April CPI Preview: +3.7% YoY Expected at 8:30 AM ET -- C …
Traders Hideout
Khamenei Vetoes Uranium Transfer as Peace Odds Surge to …
Prediction Markets & Event Contracts
Penalties in Budapest, Peace Deadline in Tehran: Arsenal …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
The Pivot Point 113.6³ — Navigating the Prediction of …
26 thanks
Sober Journey With S&P
17 thanks
The Confluence Meter: A Multi-Layered Signal Framework B …
11 thanks
NT8 color choices
10 thanks
Volume Indicators
7 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639

infe2015,

what exactly seems to be the problem?

When storing values in a multidimensional array the only difference is that you have to specify all dimensions.

For your summation you will likely have to build your own function/code that cycles through all the array elements that you want to sum using a for loop.

Regards,

ABCTG


Follow me on X Reply With Quote
  #3 (permalink)
zaruski
Salt Lake City, UT
 
Posts: 11 since Jun 2017
Thanks Given: 0
Thanks Received: 1


You can certainly achieve this using a recursive method.

BE AWARE, RECURSION CAN BE VERY SLOW AND MEMORY INTENSIVE!

Here is some C# code where I create an array with the following elements:
Element 0: Value 1
Element 1: Array with values 2 and 3
Element 2: Value 4
Element 3: Array with 2 elements:
Element 0: Array with two values: 5 and 6
Element 1: Value 7

The sum should be 28.

static void Main(string[] args)
{
object[] o = new object[4];
int value1 = 1;
object[] array1 = new object[2] {2, 3};
int value2 = 4;

object[] array_2_element_0 = new object[]{5,6};
object[] array2 = new object[2]{array_2_element_0, 7};

o[0] = value1;
o[1] = array1;
o[2] = value2;
o[3] = array2;

int sum = Sum(o);
Console.WriteLine(sum);
}

private static int Sum(object obj)
{
int result = 0;

if (obj is object[])
{
object[] arr = (object[]) obj;
foreach (object o in arr)
{
result += Sum(o);
}
}
if (obj is int)
{
result = (int) obj;
}

return result;
}


Reply With Quote
  #4 (permalink)
zaruski
Salt Lake City, UT
 
Posts: 11 since Jun 2017
Thanks Given: 0
Thanks Received: 1

Also, it just occurred to me, that you might be asking how to access array elements beyond the first dimension. It is done like this:

int x = array[0][0];

However, if you don't know how many dimensions you will have, then you must iterate through every element, rather than access elements by index.


Reply With Quote




Last Updated on August 17, 2017


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts