Code works until I iterate too many times and/or increase value too many times
조회 수: 2 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160585/image.jpeg)
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
Walter Roberson
2016년 4월 9일
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.
채택된 답변
Walter Roberson
2016년 4월 9일
format long g
and try the calculation again
댓글 수: 3
Walter Roberson
2016년 4월 9일
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 ?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!