필터 지우기
필터 지우기

Adding members to a matrix changes other members in the matrix

조회 수: 1 (최근 30일)
paul
paul 2022년 9월 13일
이동: Bruno Luong 2022년 9월 14일
Hello,
This is obviously due to my lack of understanding but cna anybody point out what i'm doing wrong here, please?
I've created a vector of odd numbers up to 25:
X = 1:2:2*13
...and then populated the first row of a matrix with that vector:
Y = [X(1:13)]
...which achieves the following:
X =
1 3 5 7 9 11 13 15 17 19 21 23 25
Y =
1 3 5 7 9 11 13 15 17 19 21 23 25
I then modified my script to add a second row to the matrix Y, which uses a function with vector X as its domain:
Y = [X(1:13) ;...
(X(1:13).^3)/factorial(3) ]
...but, when I run the script, the new line descriptor has changed the first line as well:
Y =
1.0e+03 *
Columns 1 through 12
0.0010 0.0030 0.0050 0.0070 0.0090 0.0110 0.0130 0.0150 0.0170 0.0190 0.0210 0.0230
0.0002 0.0045 0.0208 0.0572 0.1215 0.2218 0.3662 0.5625 0.8188 1.1432 1.5435 2.0278
Column 13
0.0250
2.6042
So why has it done that?
There's obviously some sort of link between the two rows, but I can't see the logic or sense in there being one...
Thanks for any help on this,
Paul
  댓글 수: 2
Stephen23
Stephen23 2022년 9월 13일
편집: Stephen23 2022년 9월 13일
"So why has it done that?"
Because the default display FORMAT uses "fixed-decimal format with 4 digits after the decimal point", and for values in an array it uses a common multiplier.
Note that this is purely an artifact of how data are displayed, of course your actual data have not changed.
"There's obviously some sort of link between the two rows, but I can't see the logic or sense in there being one..."
The link is that they are in one array, and you are displaying that array. Your data have not changed.
Walter Roberson
Walter Roberson 2022년 9월 13일
The
Y =
1.0e+03 *
means that all values displayed in the matrix need to be mentally multiplied by 1.0e+03 (that is, 1000) . So for exampled 0.0030 needs to be mentally multiplied out to get 3.0 and 0.0208 needs to be mentally multiplied out to get 20.8
This saves presentation space compared to having to put e+03 after the end of every entry, like 0.0030e+03 0.0208e+03 .

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2022년 9월 13일
It is simply the display on screen that scale the data to largest value. The data is untouched interally.
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 9월 13일
Give the command
format long g
and display Y again and you will see the original values.
paul
paul 2022년 9월 14일
이동: Bruno Luong 2022년 9월 14일
Thankyou both, that's very helpful.
I like matlab but, my goodness me, it keeps tripping me up!
Thanks for your help,
Paul

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by