multiple a vector by a scalar using dot error

조회 수: 3 (최근 30일)
Robert Scott
Robert Scott 2021년 7월 29일
답변: DGM 2021년 7월 29일
So yet another problem for my day
I am trying to multiply a simple cell array fill of ints by a scalar value
if i print out
my_array{1:end , 1}
I get a bunch of ints back
However if i say
my_array{1:end , 1} * 5
I get a "too many input arguments" error from matlab
One would assume you need element wise multiplication here
So i resort to
my_array{1:end , 1} .* 5
And guess what, same error
too many input arguments
How is that even possible?
Suggestions?

답변 (1개)

DGM
DGM 2021년 7월 29일
I guess I already mentioned this, but
A = num2cell(reshape(1:70,10,[]))
A = 10×7 cell array
{[ 1]} {[11]} {[21]} {[31]} {[41]} {[51]} {[61]} {[ 2]} {[12]} {[22]} {[32]} {[42]} {[52]} {[62]} {[ 3]} {[13]} {[23]} {[33]} {[43]} {[53]} {[63]} {[ 4]} {[14]} {[24]} {[34]} {[44]} {[54]} {[64]} {[ 5]} {[15]} {[25]} {[35]} {[45]} {[55]} {[65]} {[ 6]} {[16]} {[26]} {[36]} {[46]} {[56]} {[66]} {[ 7]} {[17]} {[27]} {[37]} {[47]} {[57]} {[67]} {[ 8]} {[18]} {[28]} {[38]} {[48]} {[58]} {[68]} {[ 9]} {[19]} {[29]} {[39]} {[49]} {[59]} {[69]} {[10]} {[20]} {[30]} {[40]} {[50]} {[60]} {[70]}
A{2:2:end,7} % this expression has multiple outputs (multiple scalars)
ans = 62
ans = 64
ans = 66
ans = 68
ans = 70
vertcat(A{2:2:end,7}) % this expression has only one output (a vector)
ans = 5×1
62 64 66 68 70
vertcat(A{2:2:end,7}) * 2 % this works
ans = 5×1
124 128 132 136 140
A{2:2:end,7} * 2 % this doesn't
Error using *
Too many input arguments.

카테고리

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

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by