Code works until I iterate too many times and/or increase value too many times
2 views (last 30 days)
Show older comments

Problem is I'm adjusting values in a 5x5x5 matrix and if we look in the first set of values (:,:,1) there are 25 values there (wrong values that got corrupted) plus a value above them saying 1.0e+03 *. The issue is not the format of the answers but that there are 26 values there and they have been corrupted.
I have a loop of code that loops about 63,000 times and a loop inside that that checks to see if a threshold has been reached and if so increments a counter in 5x5x5 structure. If threshold is low the counter increments about a thousand times and the 5x5x5 structure values go crazy, image. Notice in the screen shot of the 5x5x5 structure for the first set of values (:,:,1) there is the 5x5 data PLUS a 1.0e+03 and it has messed up the other values in that 5x5 section?!
I'm trying to figure out if it is a Matlab bug or if there is something I'm doing wrong. Thank you!
3 Comments
Walter Roberson
on 9 Apr 2016
The 1.0e+03 is not a 26th value: it is a scaling factor that is being printed out by "format short" to try to be able to fit values in compactly. "format long g" will use more screen space but will not show up like that.
Accepted Answer
Walter Roberson
on 9 Apr 2016
format long g
and try the calculation again
3 Comments
Walter Roberson
on 9 Apr 2016
1.0e+03 * is not a 26th value: it is a scale factor that "format short" uses for a compact display.
Look:
>> format short
>> 10.^(1:8)
ans =
10 100 1000 10000 100000 1000000 10000000 100000000
>> 10.^(1:9)
ans =
1.0e+09 *
0.0000 0.0000 0.0000 0.0000 0.0001 0.0010 0.0100 0.1000 1.0000
the values are not being corrupted, they are being abbreviated to fit into a small area. The 1.0e+09 * means that you need to mentally multiply what follows by 1.0e+09
Let me put it another way: if you only have about 8 characters for every field output, how would you like it to represent a range that varies by a factor of more than 10^6 ?
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!