필터 지우기
필터 지우기

Error: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

조회 수: 1 (최근 30일)
The function runs until the first deltat limit is satisfied then errors out while the other 3 deltat elements still need to run. Is there a way to fix this? Thank you.
function output=conedepth(y0)
rtop=2.5;ytop=4;yout=1;s=ytop/rtop; %initial conditions/constant conditions
deltat=[1,0.5,0.1,0.05]; day=10;
for k=1:4
n=day./deltat
y=y0;t=0; %starting level of water
for i=1:n
V=pi*y.^3/(3*s^2);
if y>=yout
delV=3*(sin(t).^2)-3*(y-yout).^1.5;
else
delV=(3*(sin(t).^2));
end
V=V+delV
y=(3*V*s^2/pi).^(1/3)
t=t+deltat;
end
VV(k,i)=V
yy(k,i)=y
tt(k,i)=t
end
end

답변 (1개)

Viren Gupta
Viren Gupta 2018년 10월 25일
The error arises at the line
VV(k,i)=V
From 'VV(k,i)' , MATLAB assumes that VV is an array/matrix. V is already a vector. Hence an element of VV must be a scalar component not a vector/array.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by