フィルターのクリア

hi i am a beginner to matlab? can anyone help me with this problem?

3 ビュー (過去 30 日間)
Koo Ian Keen
Koo Ian Keen 2019 年 4 月 8 日
編集済み: madhan ravi 2019 年 4 月 8 日
her is my function file
here is my command to run function file
  1 件のコメント
madhan ravi
madhan ravi 2019 年 4 月 8 日
編集済み: madhan ravi 2019 年 4 月 8 日
upload code instead of picture, otherwise it forces someone to type in the code for you again

サインインしてコメントする。

採用された回答

AstroGuy1984
AstroGuy1984 2019 年 4 月 8 日
The problem is in how you're indexing your velocity vector. Think about how you're defining "t". For example, the way you're calling Vpiecewise, your t vector will range from -5 to 80 in tiny increments. You are then saying to MATLAB that you want v(-5) = (the first of your if/then). In algebra class this may make sense, because you understand it to be "velocity when t=-5)".
MATLAB does not. It is going entirely on what index in the vector it is. So it doesn't understand what the -5th index is (nor will it understand a fractional index).
One solution would be to pre-allocate a vector V before your loop and index that. for example:
t = t_start:0.01:t_end;
Nt = numel(t);
v = nan(1,Nt);
for t_idx = 1:Nt
if t(t_idx) < 10
v(t_idx) = 11 * t(t_idx)^2 - 5*t(t_idx)
elseif
% etcetera...
end
end
What's happening in this case is the interation is on the number of indicies not the value of t itself like in your code. I prefer to pre-allocate my vectors as NaNs to help me spot issues, but you may choose anything you want. ones()*value can be good for this.

その他の回答 (0 件)

カテゴリ

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