Error using * (Inner matrix dimensions must agree)

조회 수: 1 (최근 30일)
Dan
Dan 2013년 11월 25일
댓글: dpb 2013년 11월 26일
This is what I have so far
if true
clear all;
clc;
close all;
t=(-.5:1*exp(-6):2);
f=6*exp(-1.5*t)*cos(8*3.14*t);
F=input('Enter a particular value for f(t): ');
Figure 1;
Plot (f,t,'r',F,t,'g');
grid on;
hold on;
end
I know my problem is at the f= line, what am I doing wrong with the *? Thanks

채택된 답변

dpb
dpb 2013년 11월 25일
doc times % or '.*'
will answer all...

추가 답변 (3개)

Dan
Dan 2013년 11월 25일
Thanks guys, for the same code I need to determine the number of times f(t) crosses the line y(t)=F using a while- end statement.
f(t) being f=6*exp(-1.5*t).*cos(8*3.14*t); and F being the input from the user.
I am not really sure how to write this? Pretty sure I am over thinking it.

Matt J
Matt J 2013년 11월 25일
f=6*exp(-1.5*t).*cos(8*3.14*t);

Dan
Dan 2013년 11월 25일
Can I do something like
if true%
x = f;
while x >= F
disp(x)
x = x + 1;
end
  댓글 수: 1
dpb
dpb 2013년 11월 26일
Not quite...the initialization sets x to the full vector of f so the while will be a vector and if F is > any value at all in f the condition will never evaluate to T.
Is it mandatory to use while? If not, consider what
diff(x>=F)
yields and how one might use something of that nature.
Note that in your sample loop, even if you set
x=f(1);
as the initialization the while doesn't work as you need and even if it did it doesn't find the crossing points.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by