Array initialization question / problem.
in
Programming Questions
•
1 year ago
Hi!
I have a question regarding how array works. I will attch a small piece of sample code so you can see what I mean.
The first case is this, in a small processing application, I declare a float array named data. I pass that float array into the function loadData which returns a float array. The returned data is of correct length and with the correct values. So far so good.
- float[] data;
- public void setup()
- {
- data = chartData.loadData("oc", loadFileGdp);
- }
But how does it work when I have a two dimensional array named data instead of a one dimensional? Like this example:
- float[][] data;
- String[] dataNames = new String[3];
- dataNames[0] = "naData";
- dataNames[1] = "euData";
- dataNames[2] = "asData";
- data = new float[dataNames.length][];
- public void setup()
- {
- for(int i = 0; i < dataNames.length; i++)
- {
- data[i][] = chartData.loadData(dataNames[i], loadFileGdp);
- }
- }
I cannot get this to work, I know there are many workarounds that I can take to make it work, but I am interested to why this is wrong, to me it seems pretty logical.
Thank you very much for your help & many thanks to the processing team!
Kind regards,
Lukas
1