MATLAB Answers

A weird display of the output

1 ビュー (過去 30 日間)
Shunhao Huang
Shunhao Huang 2020 年 7 月 10 日
回答済み: Prabhan Purwar 2020 年 7 月 13 日
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 件のコメント

サインインしてコメントする。

採用された回答

Prabhan Purwar
Prabhan Purwar 2020 年 7 月 13 日
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 件のコメント

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by