伊莉討論區

標題: MATALB 問題 高手求救一下 [打印本頁]

作者: abut0309    時間: 2013-11-17 05:09 PM     標題: MATALB 問題 高手求救一下

本帖最後由 abut0309 於 2013-11-17 05:30 PM 編輯

[attach]96684148[/attach]學校作業需求 但因為老師還沒交到那麼深的地方 也是簡單帶過目前只會使用FOR 迴圈 不會用IF END  請教各位高手了! 謝謝

作者: lineage611388    時間: 2013-11-17 06:54 PM

clear all;close all;clc

x_table = [-3 -2 -1 0 1 2 3];
x_plot = [];
y_plot = [];

for ii = 1:length(x_table)
    x = x_table(ii);
    if x<1
        y = (x-2)/(x-1);
    elseif x==1
        y = 1;
    elseif x>1
        y = (-x+2)/(x-1);
    end
   
    y_plot = [y_plot y];
    x_plot = [x_plot x];
end

figure
plot(x_plot,y_plot,'o-')




歡迎光臨 伊莉討論區 (http://a401.file-static.com/) Powered by Discuz!