A weird display of the output
2 views (last 30 days)
Show older comments
Shunhao Huang
on 10 Jul 2020
Answered: Prabhan Purwar
on 13 Jul 2020
I'm confused by the following output. Below is my code. I used pause to check the result of the last command step by step.
I(95:101,890:901,2).*(v_fix(95:101,890:901,1)-ones(7,1)*v(2,890:901))
pause()
(1-I(95:101,890:901,2))*Q
pause()
invent(:,:,1)=I(:,:,2).*(v_fix(:,:,1)-ones(a_length+1,1)*v(2,:))+(1-I(:,:,2))*Q;
invent(95:101,890:901,1)
pause()
invent(:,:,1)
pause()
I truncated the matrix, so it's easier to see the results. Here's the result for the 1st command
ans =
0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405
0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409
0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413
0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418
0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422
0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426
0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431
Here's the result of the 2nd command:
ans =
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
And the third:
ans =
0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405
0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409
0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413
0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418
0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422
0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426
0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431
And part of the final (colum 886 to 900, row 95 to 101)
0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405 0.0405
0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409 0.0409
0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413 0.0413
0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418 0.0418
0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422 0.0422
0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426 0.0426
0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431 0.0431
However, if I delete the display of invent(95:101,890:901,1),
I(95:101,890:901,2).*(v_fix(95:101,890:901,1)-ones(7,1)*v(2,890:901))
pause()
(1-I(95:101,890:901,2))*Q
pause()
invent(:,:,1)=I(:,:,2).*(v_fix(:,:,1)-ones(a_length+1,1)*v(2,:))+(1-I(:,:,2))*Q
pause()
I got the following result for the last command (colum 886 to 900, row 95 to 101):
-0.0405 -0.0405 -0.0405 -0.0405 -0.0405 -0.0405 -0.0405 -0.0405 -0.0405 -0.0405 -0.0405 -0.0405 -0.0405 -0.0405 -0.0405
-0.0409 -0.0409 -0.0409 -0.0409 -0.0409 -0.0409 -0.0409 -0.0409 -0.0409 -0.0409 -0.0409 -0.0409 -0.0409 -0.0409 -0.0409
-0.0413 -0.0413 -0.0413 -0.0413 -0.0413 -0.0413 -0.0413 -0.0413 -0.0413 -0.0413 -0.0413 -0.0413 -0.0413 -0.0413 -0.0413
-0.0418 -0.0418 -0.0418 -0.0418 -0.0418 -0.0418 -0.0418 -0.0418 -0.0418 -0.0418 -0.0418 -0.0418 -0.0418 -0.0418 -0.0418
-0.0422 -0.0422 -0.0422 -0.0422 -0.0422 -0.0422 -0.0422 -0.0422 -0.0422 -0.0422 -0.0422 -0.0422 -0.0422 -0.0422 -0.0422
-0.0426 -0.0426 -0.0426 -0.0426 -0.0426 -0.0426 -0.0426 -0.0426 -0.0426 -0.0426 -0.0426 -0.0426 -0.0426 -0.0426 -0.0426
-0.0431 -0.0431 -0.0431 -0.0431 -0.0431 -0.0431 -0.0431 -0.0431 -0.0431 -0.0431 -0.0431 -0.0431 -0.0431 -0.0431 -0.0431
I don't understand why the result suddenly turns negative. I thought the semicolon only controls whether to output the result.
0 Comments
Accepted Answer
Prabhan Purwar
on 13 Jul 2020
Hi,
That's right, the semicolon at the end only controls whether to output the result or not. It has no effect upon the output.
The error you faced is not reproducible and the above code is working as expected with our random data.
I would advise you to investigate the code at your end for any manual error.
If the condition still exists, feel free to contact.
Thanks.
0 Comments
More Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!