필터 지우기
필터 지우기

Error using reshape, Size arguments must be real integers.

조회 수: 27 (최근 30일)
Nermeen
Nermeen 2013년 6월 20일
댓글: Steven Lord 2023년 9월 12일
Hi, please, i have a question. every time i run this function on Matlab
my=repmat(mean(reshape(Y,T,N)),T,1);
i got error message saying that:
Error using Reshape.
(size arguments must be real intergers).
How can i solve this problem please ?

채택된 답변

Iain
Iain 2013년 6월 20일
You could ensure that T, and N are positive whole numbers...
  댓글 수: 3
Nermeen
Nermeen 2013년 6월 20일
(Y) is my dependant variable which include negative values.
I defined (T) before as following:
T=length(Y)/N;
so, do u think that this reason for the Error ? and if yes, what can i do ?
Thanks
James Tursa
James Tursa 2013년 6월 20일
T needs to be an integer value. If length(Y) is not a whole multiple of N, then it won't be in your equation for T.

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

추가 답변 (1개)

Yan Jiang
Yan Jiang 2023년 9월 12일
Check the type of variables T and N and verify they are integer would solve this this problem.
  댓글 수: 1
Steven Lord
Steven Lord 2023년 9월 12일
The type of T and N isn't what's important, though casting them to an integer type could accidentally resolve the problem. The values of T and N must be integer values. For example, I can reshape an array with 12 elements into a 3-by-4 array:
x = 1:12
x = 1×12
1 2 3 4 5 6 7 8 9 10 11 12
y = reshape(x, 3, 4)
y = 3×4
1 4 7 10 2 5 8 11 3 6 9 12
But I can't reshape it to have 8 columns because having an array with 1.5 rows doesn't make sense.
try
z = reshape(x, [], 8) % WILL ERROR
catch ME
fprintf("This call threw error:\n%s\n", ME.message)
end
This call threw error: Product of known dimensions, 8, not divisible into total number of elements, 12.
Trying to specify 1.5 rows will throw an error as well.
try
z = reshape(x, 1.5, []) % WILL ERROR
catch ME
fprintf("This call threw error:\n%s\n", ME.message)
end
This call threw error: Size arguments must be real integers.
Nor can I reshape it to have 0 rows.
try
z = reshape(x, 0, []) % WILL ERROR
catch ME
fprintf("This call threw error:\n%s\n", ME.message)
end
This call threw error: Product of known dimensions, 0, not divisible into total number of elements, 12.
A complex number of rows won't work either.
try
z = reshape(x, 3i, []) % WILL ERROR
catch ME
fprintf("This call threw error:\n%s\n", ME.message)
end
This call threw error: Size argument cannot be complex.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by