Subscripted assignement dimension mismatch

1 回表示 (過去 30 日間)
Markus Maier
Markus Maier 2016 年 12 月 15 日
回答済み: Markus Maier 2016 年 12 月 15 日
Hey guys i´ve just started to work with mathlab and tried to plot my sectionwise function f(t)={t for 0<=t<1, -t+2 for 1<=t<2, else 0} If i want to run my code, i got always the error " Subscripted assignement dimension mismatch". Can someone figure out whats wrong and help me to fix my code. Thx for your support.
if true
% code
end
clear t
close all
clc
t=1:0.1:5;
y(t>=0&t<1)=t;
y(t>=1&t<2)=-t+2;
y(t<0&t>=2)=0;
plot(t,y);

採用された回答

Mischa Kim
Mischa Kim 2016 年 12 月 15 日
How about
t = 1:0.1:5;
y = t.*(t>=0&t<1) + (-t+2).*(t>=1&t<2) + 0*(t<0&t>=2);
plot(t,y)

その他の回答 (1 件)

Markus Maier
Markus Maier 2016 年 12 月 15 日
thx for the quick reaction :) it works. I thought i had to write the function in sections.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by