Simple operations with vectors

조회 수: 2 (최근 30일)
Igor Braz Gonzaga
Igor Braz Gonzaga 2022년 3월 13일
댓글: Igor Braz Gonzaga 2022년 3월 13일
Hi everyone. I am begining with Matlab and I have a doubt:
Follows my code:
t=0:1/(100*fe):Tmax;
Nped=10
for i=1:Nped
for 1:lenght(t)
dist(i)=vp(i)*t;
end
end
The error that appears is: Unable to perform assignment because the indices on the left side are not compatible with the size of the right
side.
Does anyone knows how can I fix it? Thanks a lot.
  댓글 수: 1
Davide Masiello
Davide Masiello 2022년 3월 13일
What is vp? And what size are dist and vp?

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

채택된 답변

Torsten
Torsten 2022년 3월 13일
편집: Torsten 2022년 3월 13일
dist(i) is one single number (a scalar), vp(i)*t is a vector of the same length as t.
You can't assign a vector to a scalar element.
Do you mean
t = 0:1/(100*fe):Tmax;
Nped = 10;
for i = 1:Nped
for j = 1:lenght(t)
dist(i,j)=vp(i)*t(j);
end
end
or simply
t = 0:1/(100*fe):Tmax;
Nped = 10;
for i = 1:Nped
dist(i,:) = vp(i)*t
end
or even simpler
t = 0:1/(100*fe):Tmax;
dist = v.*t
if v is a column vector ?
?
Or maybe
t = 0:1/(100*fe):Tmax;
Nped = 10
for i = 1:Nped
dist{i} = vp(i)*t;
end
  댓글 수: 1
Igor Braz Gonzaga
Igor Braz Gonzaga 2022년 3월 13일
Hi Torsten , Thanks a lot. It works very well !!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by