Well, you have two global arrays totaling 3840 bytes. You have 8k on your Mega so in principle you should be able to get this to work.
As @UKHeliBob implies above: don't use Strings for starters.
Also, please post the error you're apparently getting.
Sketch uses 12730 bytes (5%) of program storage space. Maximum is 253952 bytes.
Global variables use 7108 bytes (86%) of dynamic memory, leaving 1084 bytes for local variables. Maximum is 8192 bytes.
Low memory available, stability problems may occur.
No the arrays occupy 6240 bytes ( 65x32x3 ). One array is int and the other byte.
And the SD lib needs a lot of ram too.
That's too much, even for a Mega. Even worse with the usage of String, which needs ram on the heap ( which is additionally to globals ).
The common workaround for a similar memory problems is to divide the data in parts.
As an example, instead of fulfilling the entire 65x32 array and then storing it to the SD, you would work with it row by row: insert a first 32 values to a single-row 1x32 array and write it to SD, then put a next 32 values to the same array and put them to the SD and so on
I was mistaken.
(I was wrong. The problem is simply that there are too many variables and there is not enough memory. The problem is not that the 'for function' was performed...)
This is not a problem with the 'SD library' or 'for function', but a memory problem solely based on variables.
Let's look for improvements.
thank you for the reply.
Why not save it as a uint8_t and do the multiplying only at the moment it's necessary (e.g. when they're being displayed)? There's no sense in storing redundant data; in this case the trialing zeroes of the multiplied integer. For your program, things will work the same if you store values of 1, 2, 3, 10, 255 and then multiply them to 10, 20, 30, 100 and 2550. But if you store the multiplied values (both in an array and on your card), they'll take up twice as much space.
OK, so assuming the actual arrays are [40][32], the root cause of your problem is not so much in these two arrays (they fit easily in your Mega's memory, with room to spare), but also what happens in the rest of your sketch. Memory management is often a balancing act; it's a budget and you have to allocate it to where it's needed the most, and compromise where you can. See the "multiply by 10" issue above.
Thanks for the advice.
This method has 0~255 in memory, but
In the code, you can assume that the virtual value is 10 to 2550.
To take a simple example,
float result = 0;
uint16_t
result = (float)X1 * 0.1; // actual calculation expression
float result = 0;
uint8_t
result = (float)X1 * 1.0; // virtual coding, How to bypass
It should be used as assumed above. This seems to be the answer for now.
It may be a matter of how you approach the job. On a PC, tendency is to "grab it all, then process it all". On a micro, it's usually better to grab a bit, process it, iterate until done. If at all possible, rethink your approach that way. Even a menu system can sometimes be partitioned into sections and read when needed, though that can get painful, when it is easier to just push fixed text off into program space.
Here you use a 4-byte data type to store 1 byte of actual information. I feel you're juggling data types around without sufficiently realizing the implications. I bet if you remove all such inefficiencies from your code, it'll run just fine.
How 'real'? Which is to say: what kind of actions do you need to perform on the data and how much time do you have for it? I bet there's more leeway than you think. And if there isn't, you've probably selected the wrong platform for the task - if you're doing something that involves really fast interactions with the outside world and moderately large amounts of data, there's not much sense in trying to cram everything into a fairly old-fashioned microcontroller. It seems you're painting yourself into a corner and as a result eliminating solutions that in reality would actually work.