필터 지우기
필터 지우기

I keep getting this error : Matrix dimensions must agree. Error in comp (line 5) c(x)=0.5.*​erfc(x./(2​*sqrt(u.*t​)));

조회 수: 2 (최근 30일)
I'm trying to write a for loop that plots the function c(x) for each value of t, but I keep getting this error. " Matrix dimensions must agree. Error in comp (line 5) c(x)=0.5.*erfc(x./(2*sqrt(u.*t)));"
t = [1 24 48 72];
x=0:1;
for ii = length(t)
u=1.656e-5;
c(x)=0.5.*erfc(x./(2*sqrt(u.*t)));
plot c
end
  댓글 수: 1
Bish Erbas
Bish Erbas 2018년 9월 27일
Please format your code by selecting the code and clicking on the Code button in the formatting toolbar.

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

채택된 답변

Bish Erbas
Bish Erbas 2018년 9월 27일
편집: Bish Erbas 2018년 9월 27일
x and t vectors must have same dimensions since you are performing an element-by-element multiplication. In your code, x = [0 1] and t = [1 24 48 72]. If what you need is an x vector that spans from 0 to 1 linearly, you can specify x = linspace(0,1,4);. In other words, just make sure t and x are of the same dimensions.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by