Help with for loop and invalid expression
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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')
0 comentarios
Respuestas (1)
Dave B
el 6 de Ag. de 2021
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!
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!