フィルターのクリア

Help with for loop and invalid expression

1 回表示 (過去 30 日間)
Az Naqvi
Az Naqvi 2021 年 8 月 6 日
回答済み: Dave B 2021 年 8 月 6 日
Hi, I'm currently stuck on this loop and I'm getting an inalid expression error at the moment. Would be greatful if someone could help me resolve it please.
m=458
n= 2
t = 30
for i=1:m
for j=1:n
x = 1.4*sin(t^1.6) + 0.3*tan(t^1.3)
t = t+0.01
a(i,j)=(t,x) %this is where the first error occurs
end
end
a=reshape(a,m,n)
figure
hold on
plot(a,Linespace)
title('Displacement vs time')
v = reshape(a,m,n);
b = reshape(a.m.n)
for i in x:
if(x(1,i) >20)
v = x(1,i)
else
b = x(1,i)
end
end
figure
hold on
plot(v,Linespace,'g')
plot(b,Linespace,'r')
title('Displacement vs time')

回答 (1 件)

Dave B
Dave B 2021 年 8 月 6 日
The line of code
a(i,j)=(t,x);
doesn't make sense. a(i,j) is a location in a matrix, namely the ith row and jth column of the matrix a. You can only store one value there. So you can do:
a(i,j) = t;
or
a(i,j) = x;
or even
a(i,j,1:2)=[1 2]; % if a was a 3 dimensional matrix
My guess is leave the t out of the loop, it looks like it's something like:
t = 0:.01:(numel(a)-1)*.01;
Once you've done that, you'll realize you can probably leave the assignment of the loop:
a = 1.4.*sin(t.^1.6) + 0.3.*tan(t.^1.3);
% but I'll leave it to you to figure out how big t should be without
% relying on numel(a). It's pretty simple!

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by